please look upto my code and tell me my the last case shows TLE
Here’s the github gist
please look upto my code and tell me my the last case shows TLE
Here’s the github gist
use little fermate theorem…
you cannot check if a number is prime or not with this method if number is as large as 2^64
ok thanks I will try that way
i guess the last test case has been designed so that it fails the probabilistic algo …then what do i do??
no it wont fail… just take care of overflow while multiplying large number…
yes I took care of it using modulo exponentiation but it still fails
a = 1e14 + 1
b = 1e4 + 2
c = 1e15
how will you evaluate (a*b)%c ?
But c was supposed to be 10e9+7,
In the case you mentioned it will overflow
in little fermate c is not equal to 1e9+7 c is the number and number can vary upto 1e18. thats why i told you to take care of overflow while multiplying large number.
see my code how to handle such situation
got my mistake in this part !!