博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PTA-1015——Reversible Primes
阅读量:4690 次
发布时间:2019-06-09

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

题目:

A 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 (<) and D (1), 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

分析:

进制转换,一个注意点:1不是素数,不然会卡在第二个测试点

代码:

1 #include
2 #include
3 using namespace std; 4 long long x; 5 int n,d; 6 bool judge(long long x){ //判断是否为素数 7 int i; 8 for(i=2;i<=sqrt(x);i++){ 9 if(x%i==0){10 break;11 }12 }13 if(i>sqrt(x)&&x>=2){14 return true;15 }else{16 return false;17 }18 }19 int main(){20 while(cin>>n&&n>=0){21 cin>>d;22 x=0;23 if(!judge(n)){24 cout<<"No"<

 

 

转载于:https://www.cnblogs.com/orangecyh/p/10307373.html

你可能感兴趣的文章
java文件上传和下载
查看>>
SQL联合查询(内联、左联、右联、全联)的语法(转)
查看>>
枚举和实用类
查看>>
python基础知识第二篇(字符串)
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
redis数据结构--String
查看>>
POJ 3279 Fliptile (二进制枚举)
查看>>
memcached 细究(三)
查看>>
future
查看>>
关于main函数传参数的问题
查看>>
getTickCount()函数 VS GetTickCount()函数
查看>>
嵌入式jetty
查看>>
2017~回顾分享
查看>>