#T668. 伪质数

伪质数

Description

Fermat's Little Theorem: Suppose \( a \) is an integer and \( p \) is a prime number, then \( a^p - a \) is a multiple of \( p \), which can be expressed as \( a^p \equiv a \ (\text{mod} \ p) \). If \( a \) is not a multiple of \( p \), this theorem can also be written as \( a^{p-1} \equiv 1 \ (\text{mod} \ p) \), a more commonly used form. However, there exist some composite numbers \( p \) that satisfy \( a^p \equiv a \ (\text{mod} \ p) \) for specific values of \( a \). Such numbers are called pseudoprimes to base \( a \).

Given \( 2 \leq p \leq 10,000,000,000 \) and \( 1 < a < p \), determine whether \( p \) is a pseudoprime to base \( a \).

Input Format

Each test case contains multiple sets of input data. Each set consists of a line with two space-separated integers \( p \) and \( a \). The input ends with two zeros.

Output Format

For each set of data, output "yes" if \( p \) is a pseudoprime to base \( a \), otherwise output "no".

```input1 10 3 341 2 341 3 0 0 ``` ```output1 no yes no ``` ## 来源

CodesOnline