经典简约
清爽简洁,回归本真
液态水晶
毛玻璃+霓虹光带
赛博朋克
霓虹故障艺术风
🚫
违规操作检测
禁止使用右键菜单
⚠️ 此操作已被系统记录
1

Pseudoprime numbers

📝 题解 🔵 仅限 C++
题目描述
<p><img src="http://plg1.cs.uwaterloo.ca/~acm00/070923/fermat.jpg" style="width: 596px; height: 386px;" alt="" /></p> <p>&nbsp;</p> <p>Fermat's theorem states that for any prime number <i>p</i> and for any integer <i>a &gt; 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 &lt; p &le; 1,000,000,000</i> and <i>1 &lt; a &lt; 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 &quot;0 0&quot;. Each test case consists of a line containing <i>p</i> and <i>a</i>. For each test case, output &quot;yes&quot; if p is a base-a pseudoprime; otherwise output &quot;no&quot;.</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
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这道题,可以帮你分析思路、提供代码示例。
⚠️ 请先登录后使用