PAT 甲级 1015 Reversible Primes
发布日期:2021-07-01 03:08:51 浏览次数:2 分类:技术文章

本文共 1905 字,大约阅读时间需要 6 分钟。

1015 Reversible Primes (20 point(s))

reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.

Now given any two positive integers N (<10​5​​) and D (1<D≤10), you are supposed to tell if N is a reversible prime with radix D.

Input Specification:

The input file consists of several test cases. Each case occupies a line which contains two integers N and D. The input is finished by a negative N.

Output Specification:

For each test case, print in one line Yes if N is a reversible prime with radix D, or No if not.

Sample Input:

73 1023 223 10-2

Sample Output:

YesYesNo

Experiential Summing-up

This question must be clearly read. The definition of reversible prime is a number which is prime and the decimal form of the reverse of the number's corresponding number in specified radix is also a prime.Certainly annoyed.However, only understanding this will you pass all test points.

(The purpose of using English to portray my solution is that to exercise the ability of my expression of English and accommodate PAT advanced level's style.We can make progress together by reading and comprehending it. Please forgive my basic grammar's and word's error. Of course, I would appreciated it if you can point out my grammar's and word's error in comment section.( •̀∀•́ ) Furthermore, Big Lao please don't laugh at me because I just a English beginner settle for CET6    _(:з」∠)_  )

Accepted Code

#include 
const int maxn=100010;bool flag[maxn]={false};void find_prime(){ flag[0]=flag[1]=true; for(int i=2;i
=0;--i) { ans+=z[i]*product; product*=d; } return ans;}int main(){ int n,d; find_prime(); while(~scanf("%d",&n)) { if(n<0) break; scanf("%d",&d); int res=convert(n,d); printf("%s\n",flag[res]==false&&flag[n]==false?"Yes":"No"); } return 0;}

 

转载地址:https://meteorrain.blog.csdn.net/article/details/86547858 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT 甲级 1016 Phone Bills
下一篇:PAT 甲级 1014 Waiting in Line

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月26日 09时59分55秒