题目描述
<p><img src="http://plg1.cs.uwaterloo.ca/~acm00/070923/fermat.jpg" style="width: 596px; height: 386px;" alt="" /></p> <p> </p> <p>Fermat's theorem states that for any prime number <i>p</i> and for any integer <i>a > 1</i>, <i>a<sup>p</sup> == a (mod p)</i>. That is, if we raise <i>a</i> to the <i>p</i>th power and divide by <i>p</i>, the remainder is <i>a</i>. Some (but not very many) non-prime values of <i>p</i>, known as <i>base-a pseudoprimes</i>, have this property for some <i>a</i>. (And some, known as Carmichael Numbers, are base-a pseudoprimes for all <i>a</i>.)</p> <p>Given <i>2 < p ≤ 1,000,000,000</i> and <i>1 < a < p</i>, determine whether or not <i>p</i> is a <i>base-a pseudoprime</i>.</p> <p>Input contains several test cases followed by a line containing "0 0". Each test case consists of a line containing <i>p</i> and <i>a</i>. For each test case, output "yes" if p is a base-a pseudoprime; otherwise output "no".</p>
输入格式
输出格式
样例
样例输入 1
3 2
10 3
341 2
341 3
1105 2
1105 3
0 0
样例输出 1
no
no
yes
no
yes
yes
提交代码
请先登录后提交
🤖 AI 解题助手
DeepSeek
就绪