1015 Reversible Primes (20 分)
 

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 10
23 2
23 10
-2

Sample Output:

Yes
Yes
No

题目大意:

一开始理解错了题意。。。。
数字N在D进制下是不是双重素数。双重素数是本身和倒数皆为素数的数。

实现:判断N是否为素数。如果不是,输出No,否则将该数在D进制下倒过来再化为十进制数,判断是否为素数。如果是,输出Yes,否则输出No.

复习判断素数知识点 注意 ‘ = ’ !!!

#include<bits/stdc++.h>
using namespace std;
bool prime(int x){
if(x==||x==){
return false;
}
if(x==){
return true;
}
for(int i=;i<=sqrt(x);i++){//这个地方忘记了=号!!!
if(x%i==){
return false;
}
}
return true;
}
int main()
{
int a;
int d;
while(cin>>a)
{
if(a<){
break;
}
cin>>d;
//先判断本身是不是素数
if(!prime(a)){
cout<<"No"<<endl;
continue;
}
//根据相应地进制转
string s="";
int x;
while(a){
s+=char(a%d+'');
a=a/d;
}
//cout<<s<<endl; //反向再把它从d进制转成10进制
int l = s.length();
x=;
for(int i=;i<l;i++){
x=x*d+s[i]-'';
}
//cout<<x<<endl;
if(prime(x)){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return ;
}
 

PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))的更多相关文章

  1. PAT-1015 Reversible Primes (20 分) 进制转换+质数

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  2. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  3. PAT 1015 Reversible Primes[求d进制下的逆][简单]

    1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...

  4. PAT 甲级 1015 Reversible Primes(20)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  5. PAT Advanced 1015 Reversible Primes (20) [素数]

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  6. PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  7. 【PAT甲级】1015 Reversible Primes (20 分)

    题意: 每次输入两个正整数N,D直到N是负数停止输入(N<1e5,1<D<=10),如果N是一个素数并且将N转化为D进制后逆转再转化为十进制后依然是个素数的话输出Yes,否则输出No ...

  8. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

  9. 1015 Reversible Primes (20 分)

    A reversible prime in any number system is a prime whose "reverse" in that number system i ...

随机推荐

  1. zabbix low-level discovery 监控mysql

    当一台服务器上MySQL有多个实例的时候,MySQL占用多个不同端口.利用zabbix的low-level discovery可以轻松监控. 思路参考:http://dl528888.blog.51c ...

  2. 控制台警告libpng warning: iCCP: known incorrect sRGB profile

    用控制台测试数据的时候,出现的这个问题.虽然只是一个警告但是看着就是不太舒服 ,见下图 弄了好长时间,无意间切换个输入法,原先使用的是QQ输入法 切换成微软五笔以后,竟然好了 好了 好了

  3. mongodb的基本操作之数据创建索引

    在数据量较少时,不使用索引,查询是很快的,但是在数据量较大时,查询将会变得非常缓慢,在mongodb中 查看索引 > db.test_collection.getIndexes() [ { &q ...

  4. 前端与SQL

    转载自:http://developer.51cto.com/art/201706/542163.htm

  5. redis过期机制及排行榜

    redis 内存数据集大小上升到一定大小的时候,就会施行数据淘汰策略.redis 提供 6种数据淘汰策略:  volatile-lru:从已设置过期时间的数据集(server.db[i].expire ...

  6. android-studio打包APK出现有关apk图标问题

    报的错很多,有build gradle中的两个大红感叹号,由此引发了一大堆问题 注意到最后出现红色打包错误的代码: Failed to read PNG signature: file does no ...

  7. [2019HDU多校第二场][HDU 6591][A. Another Chess Problem]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6591 题目大意:二维坐标系上,所有满足\(5|2x+y\)的点都被设为障碍物,无法通过.现给出一对点, ...

  8. GET 和 POST is so different

    .原理区别 一般我们在浏览器输入一个网址访问网站都是GET请求;再FORM表单中,可以通过设置Method指定提交方式为GET或者POST提交方式,默认为GET提交方式. HTTP定义了与服务器交互的 ...

  9. MySQL数据库有几种索引?分别是什么?

        5种索引     1.主键索引     2.唯一索引     3.普通索引     4.全文索引     5.联合索引

  10. 【csp模拟赛6】相遇--LCA

    对于30%的数据:暴力枚举判断 对于60%的数据:还是暴力枚举,把两条路径都走一遍计一下数就行,出现一个点被访问两次即可判定重合 对于100%的数据:找出每条路径中距离根最近的点(lca),判断这个点 ...