Hello everyone.
On yesterday's contest I implemented a exponentiation function.
long long pow(long long n, long long k) {
n %= MOD;
if(k == 0) return 1;
if(k&1) return (n*(pow(n*n, k/2))%MOD)%MOD;
return pow(n*n, k/2) %MOD;
}
long long get(long long n) {
long long t = (n * pow(2, n-1));
t %= MOD;
return t;
}
Which for some reason it returning a double when the exponent is high enough.
Why could this be?
Click
Thank you!
This happened because there is pow function in cmath(it returns double). That's why it's better to name function bin_pow(for example).
You are right, thank you
It mixed with std's pow, click
Damm, wasted so much time on this. Thank you
That happen because c++ standard library includes its own pow, and this pow receive two double parameters, so when you call it
pow( 2, 30 )
match with c++ function, so if you use cast (see previous comment)pow( 2LL, 30LL )
match with your implemented function.Thank you!