I am doing a problem on UVa. The problem statement is as follows:
We have to find nth root of a number p, and there exists an integer k such that k^n=p. So basically we have to find integer k.
Constraints:
p<10^101, n<200, k<10^9.
All variables are integers and positive.
The AC solution to the problem in c simply calculates,
pow(p,1/n);
i know double can hold data upto e308, but as far as i know upto a precision of 15 decimal places.
So my question is why the solution above works, can’t there be any precision error?
the number 10^101 looks very big. if n were 2 you could not store k anywhere.
but if you look at the other constraints – k is limited to 10^9. that takes 30 bits of an unsigned type. the mantissa of a double can easily hold that.