I couldn’t find any error but still our precious chef’s compiler gives error to my code.
Problem link
My Solution
Thanks in Advance.
I couldn’t find any error but still our precious chef’s compiler gives error to my code.
Problem link
My Solution
Thanks in Advance.
You did a couple of mistakes.
n is <= 10^18 ,so use long long.(you used int)
Since n is <=10^18 ,your pow() function will result in overflows.Hence,use modular exponentiation.
Refer Modular Exponentiation
And your condition of weight w is wrong-maximum weight can be 8 and not 9, and minimum weight can be (-9) and not -8.
And in your first condition (w>0), we do (9-w) even for w=0, so change it to (w>=0)
Also ,use (ab)%M=((a%M)(b%M))%M to avoid overflows. Check this