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. 用js刷剑指offer(变态跳台阶)

    一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 牛客网链接 思路 假设青蛙跳上一个n级的台阶总共有f(n)种跳法. 现在青蛙从第n个台阶 ...

  2. Go语言中的defer

    可以用作一些资源的释放. 1.在一个函数内的defer执行顺序是先写的后执行,后写的先执行(遵循栈结构) func DeferTest1(){ defer fmt.Println("我是 d ...

  3. 版本问题---cuda和tensorflow的版本对应关系

    cuda和tensorflow的版本有对应关系 https://tensorflow.google.cn/install/source#linux

  4. WPF绑定功能常用属性介绍

    1.Mode 绑定中数据流的方向(enum BindingMode) 目标属性指的是控件的属性 (1)TwoWay 更改源属性或目标属性时,会自动更新另一方.适用于可编辑窗体 例:TextBox (2 ...

  5. linux下禁止root远程登录

    一.添加和root权限一样的用户 1. adduser admin passwd  admin (修改密码) 2.修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示 ...

  6. windows下mysql5.6.x的日志正确配置方法(my.ini) (网上的都是5.6之前的版本)

    https://blog.csdn.net/databatman/article/details/49951853 感谢楼主,找了好久,试了一下楼主的,果然是对的,网上的日志配置都是5.6之前的版本: ...

  7. Java8-Lock-No.01

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...

  8. C# IFormattable 接口重写

    public class Racer : IComparable<Racer>, IFormattable { public int Id { get; private set; } pu ...

  9. EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配

    EF非常见错误:EXECUTE 后的事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配 问题原因: 两个表A\B之间存在外键关系,当插入表A的时候,A的外键B在B表中不存在可以引起这个问题: ...

  10. Jenkins 自动化构建

    def pipeId = 1130561944231279390 def pipeLogId def isTagOrBranch def tagOrBranch def imageId def add ...