11287 - Pseudoprime Numbers


Difficulty : medium

Solution Description :

Prime number & Big mod related problem

First pre-generate prime number up to 31623 you got 3401prime number between 1 and 31623

For input p and a
If p is prime then print "no" (check p is prime using the pre-generated prime list)

Otherwise you need to calculate a^p%p value using big mod algorithm
If a^p%p == a then print "yes"
Otherwise print "no"
 
Use long long for big mod calculation