(a/b)%c when c is a prime number

how to calculate (a/b)%c when c is a prime number?

You have to use fermats little theorem
Basically what it says is

(a/b)%m= (a * (b^(m-2)))%m
provided m is prime 
Here note that 10e9+7 which is used in most contets is prime

Read more about it here-


And here is the solution to the question PALLIND which you are most probably refering to-
https://www.codechef.com/viewsolution/18368200

1 Like