0
Help me solving this code
We have a Boolean function which give true as an output when there exists any x^i= n. Where i and n are given and false otherwise! Write a program without help of math library except .pow
4 Answers
+ 2
Do you want to be helped or to solve the problem for you?
+ 2
#include<iostream>
#include<cmath>
using namespace std;
bool isPow(int x, int i, int n){
return pow(x,i) == n;
}
int main() {
if (isPow(3, 2, 9)) cout<<"true"; else cout<<"false";
return 0;
}
https://code.sololearn.com/cp0yUnjBL9EQ
+ 1
you don't say anything about variable x so I wrote code consider that x, i and n are given
#include<iostream>
#include<cmath>
using namespace std;
bool f(int x,int i,int n){
return pow(x,i) == n;
}
int main(){
return 0;
}
0
The isPow method aims to investigate whether there is a strictly positive basis for the parameters nand ia strictly positive basisxâN+x \in \mathbb{N}^{+}xâN+ so that: xi=n x^{i} = nxi=n. Does such a thing existxxx, we give it trueback, otherwise false. The method only handles non-negative ones i, ie if ithis criterion is not met, the default value is falsereturned. A (naive) iterative implementation is sufficient for this task. You can find the function in the template so that you can implement this without having to import the power function from Javaâs own library pow. Use this method to calculate the power:pOw(a,b)=ab pow(a, b) = a^{b}pow(a,b)=ab
Here is an example: Be i=3i = 3i=3 and n=8n = 8n=8. isPow(3, 8)are trueback, asxi=23=8=n x^{i} = 2^{3} = 8 = nxi=23=8=n. Thus there is a strictly positive onex=2x=2x=2.
Entries withnâ€109n \ leq 10 ^ 9nâ€109 and iâ€10i \ leq 10iâ€10 must be treated correctly and efficiently.