In the shadows of Prime City, the Pseudoprime Hunter seeks numbers that fool the Fermat primality test. A composite number n is a Fermat pseudoprime to base a if a^(n-1) Ôëí 1 (mod n), even though n is not prime. Such numbers are "liars" ÔÇö they pretend to be prime. "Fermat's Little Theorem says a^(p-1) Ôëí 1 (mod p) for prime p and gcd(a,p)=1," the Hunter explains. "But some composites also satisfy this for certain bases. These are pseudoprimes. Find them, and expose their deception." Given a composite number n and a base a, determine if n is a Fermat pseudoprime to base a. Output "yes" if a^(n-1) Ôëí 1 (mod n) and n is composite, "no" otherwise. Constraints: 4 <= n <= 10^12, 2 <= a <= 10^9 Input: 341 2 Output: yes Input: 15 2 Output: no
Constraints:
4 <= n <= 10^12, 2 <= a <= 10^9
Tags:
