Classic
Clean & simple
Crystal
Glassmorphism + Neon
Cyberpunk
Neon glitch art
🚫
违规Action检测
禁止Use右键菜单
⚠️ 此Action已被系统记录
1

Pseudoprime numbers

📝 Solutions 🔵 仅限 C++
Problems Description
<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>
Input格式
Output格式
Sample
Sample Input 1
3 2 10 3 341 2 341 3 1105 2 1105 3 0 0
Sample Output 1
no no yes no yes yes
Submit Code
请先Login后Submit

🤖 AI 解题助手

OpenRouter
就绪
👋 你好!我是 AI 解题助手。
我已阅读了这problems题,可以帮你points析思路、提供Code示例。
🔓 完全Free · 无需消耗 Token