[Solved] Write an algorithm to efficiently find all i and j for any given N such that N=i^j
Given that i^j=N, you can solve the equation for j by taking the log of both sides:j log(i) = log(N) or j = log(N) / log(i). So the algorithm becomes for i=2 to N { j = log(N) / log(i) if((Power(i,j)==N) print(i,j) } Note that due to rounding errors with floating point calculations, you might … Read more