#SP0000258. Số giả nguyên tố (Pseudoprime)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số giả nguyên tố (Pseudoprime)
Pseudoprime
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Some composite integers pass a primality test based on Fermat’s theorem even though they are not prime. Such numbers are called base-dependent pseudoprimes.
You are given two integers and . Determine whether both of the following properties hold:
- is composite (greater than one but not prime).
- The remainder of upon division by equals , equivalently .
The answer is yes only if both properties hold. If is prime, the answer is no even if the Fermat congruence holds.
Input
One line with two integers and , in that order.
Output
Print exactly yes if is a base- pseudoprime, and no otherwise. Use lowercase letters.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Example 1
Input
3 2
Output
no
Explanation
The number is prime. A pseudoprime must be composite, so the output is no.
Example 2
Input
341 2
Output
yes
Explanation
The factorization shows that is composite. We also have , so . Because , we obtain . Both conditions hold, so the answer is yes.
Example 3
Input
341 3
Output
no
Explanation
is composite, but modular exponentiation gives , so the output is no.
Example 4
Input
1105 2
Output
yes
Explanation
is composite and , so the answer is yes.