Exactly the same method 
Did everything almost the same but then too tle…plz help
PLZZ SUGGEST ANY WAYS TO REMOVE TLE IN FUNC…
SOLN LINK… :-- CodeChef: Practical coding for everyone
THNX IN ADVANCE
I couldn’t find any single test case for which my code give wrong ans…please tell me the error in code.
There is one more way to do this question, view my accepted solution. Using pow() function and using fast exponent method to find a^b, where a and b are integers. CodeChef: Practical coding for everyone.
A few doubts:
- computing pow(x,i/i) while traversing over the array upto 61 indices. Would it be costly for each query?
- What you are saying is it that we should compute 1…to…10^6 raised to power 3…to…60, and then as per x and i(used for iteration and determining the i/i th power) search for a p(1…10^6) and look for the value closest to that of x(less than or equal to)
- Had there been more limitation on space, would calculating upto upto x^5(as we did the sqrt(x) in current solution) we could have done it in space of 10^3 and 6-60?
if the statements are a bit confusing i will restate them.
When we need to find that whether p^q<=x.Can we not do it in O(1) by finding whether q*LOG§<=LOG(x).
nth root can be calculated by using following formula
fun(ll x, ll n) {
return pow(10,double(log10(x)/n));
}
it gives ac to my solution
1
3 1
4 5 6
1000000
Your code gives Wrong answer atleast for this Test Case
Thanks a lot that helped me, I have struggled for this problem from last 2 days with so many WA
your EPS is probably too small. try increasing it, as you only need the integer part of the root.
i think your o[] vector is wrong. o[1] should be 10^18, o[2] =sqrt(10^18)=10^9 … you missed the first root: no root at all => j = 1
@caioaao-thanks for answering, but in the code, o[j] contains the overflow value x such that x^(j+1) is just less than or equal to 10^18
(my code works for the test case given in the problem)
try this on your nth root implementation then, right after the while loop:
Yes it is possible.
To find the nth root of x, find y = pow(x, 1.0/n)
Because of precision errors, the answer could be either y rounded up or down. So lo = y and hi = (y+0.5)
Check if pow(hi, n) <= x, if yes, hi is the root else lo is the root.
2 pow calls to find one root.
I managed to get AC with that
CodeChef: Practical coding for everyone
the only thing I can see that’s different in your implementation is that you’re not testing if ans < 0 (see first two comments in CodeChef: Practical coding for everyone).
try printing (ans+MOD)%MOD to ensure it’ll never be negative. other than that I can’t see anything wrong in your implementation, and all I’ve tested using your code gives the same output as my AC implementation.
@sudip1401
i did something on the similar lines but am getting tle…
why?
http://www.codechef.com/viewsolution/4108853