What's wrong in this code????

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.

  1. n is <= 10^18 ,so use long long.(you used int)

  2. Since n is <=10^18 ,your pow() function will result in overflows.Hence,use modular exponentiation.
    Refer Modular Exponentiation

  3. 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.

  4. And in your first condition (w>0), we do (9-w) even for w=0, so change it to (w>=0)

  5. Also ,use (ab)%M=((a%M)(b%M))%M to avoid overflows. Check this

  6. See your modified solution getting AC

2 Likes