PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000260. Số giả nguyên tố theo cơ số (Pseudoprime Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số giả nguyên tố theo cơ số (Pseudoprime Numbers)

Pseudoprime Numbers

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Fermat’s theorem implies ap≡a(modp)a^p\equiv a\pmod p for prime pp. Certain composite values also satisfy that congruence; these are called base-aa pseudoprimes.

You are given two integers pp and aa. Determine whether both of the following properties hold:

  • pp is composite (greater than one but not prime).
  • The remainder of apa^p upon division by pp equals aa, equivalently ap≡a(modp)a^p\equiv a\pmod p.

The answer is yes only if both properties hold. If pp is prime, the answer is no even if the Fermat congruence holds.

Input

One line with two integers pp and aa, in that order.

Output

Print exactly yes if pp is a base-aa pseudoprime, and no otherwise. Use lowercase letters.

Subtasks

  • Subtask 1 (20 points): 3≤p≤50003\le p\le5000; 2≤a<p2\le a<p.
  • Subtask 2 (30 points): 3≤p≤1000003\le p\le100000; 2≤a<p2\le a<p.
  • Subtask 3 (50 points): 3≤p≤1093\le p\le10^9; 2≤a<p2\le a<p.

Examples

Example 1

Input

3 2

Output

no

Explanation

The number p=3p=3 is prime. A pseudoprime must be composite, so the output is no.

Example 2

Input

341 2

Output

yes

Explanation

The factorization 341=11⋅31341=11\cdot31 shows that 341341 is composite. We also have 210=1024=3⋅341+12^{10}=1024=3\cdot341+1, so 210≡1(mod341)2^{10}\equiv1\pmod{341}. Because 341=34⋅10+1341=34\cdot10+1, we obtain 2341=(210)34⋅2≡2(mod341)2^{341}=(2^{10})^{34}\cdot2\equiv2\pmod{341}. Both conditions hold, so the answer is yes.

Example 3

Input

341 3

Output

no

Explanation

341341 is composite, but modular exponentiation gives 3341 mod 341=168≠33^{341}\bmod341=168\ne3, so the output is no.

Example 4

Input

1105 2

Output

yes

Explanation

1105=5⋅13⋅171105=5\cdot13\cdot17 is composite and 21105 mod 1105=22^{1105}\bmod1105=2, so the answer is yes.