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 (< 105) 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 10
23 2
23 10
-2

Sample Output:

Yes
Yes
No
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int numReverse(int N, int radix){
int num[], temp, index = , ans = ;
do{
temp = N % radix;
num[index++] = temp;
N = N / radix;
}while(N != );
for(int i = index - , P = ; i >= ; i--){
ans += num[i] * P;
P = P * radix;
}
return ans;
}
int isPrime(int N){
int sqr = (int)sqrt(N * 1.0);
if(N == )
return ;
for(int i = ; i <= sqr; i++){
if(N % i == )
return ;
}
return ;
}
int main(){
int N, D, N2;
while(){
scanf("%d", &N);
if(N < )
break;
scanf("%d", &D);
int temp = numReverse(N, D);
if(isPrime(N) && isPrime(temp))
printf("Yes\n");
else printf("No\n");
}
cin >> N;
return ;
}

总结:

1、判断素数:

int isPrime(int N){
int sqr = (int)sqrt(N * 1.0); //N应该转换为小数
if(N == ) //当N = 1时应返回false,容易忽略,1不是素数
return ;
for(int i = ; i <= sqr; i++){ //i <= sqr; i从2开始查找
if(N % i == )
return ;
}
return ;
}

A1015. Reversible Primes的更多相关文章

  1. PAT A1015 Reversible Primes (20 分)——进制转换,质数

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

  2. PAT甲级——A1015 Reversible Primes

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

  3. PAT_A1015#Reversible Primes

    Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...

  4. PAT 1015 Reversible Primes

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

  5. PAT 甲级 1015 Reversible Primes(20)

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

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

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

  7. PTA (Advanced Level) 1015 Reversible Primes

    Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...

  8. pat1015. Reversible Primes (20)

    1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A r ...

  9. pat 1015 Reversible Primes(20 分)

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

随机推荐

  1. vue路由\导航刷新后:ative\localStorage\url截取参数

    <el-menu :default-active="$route.path" router mode="horizontal"> <el-me ...

  2. 【Beta阶段】第九次Scrum Meeting!(论坛已成功上线)

    每日任务内容: 本次会议为第九次Scrum Meeting会议~ 本次会议为团队项目第九次会议,在会议前大家取得了重大成果! 队员 昨日完成任务 明日要完成任务 刘乾 #179 完成1021的数据处理 ...

  3. 在Java中执行Tomcat中startup.bat

    问题:更改数据库时,需要重启Tomcat服务器,才能把更改后的数据加载到项目中.于是想每次更改数据库时,都调用Java方法,重启Tomcat 代码: Process process = Runtime ...

  4. ppm\℃是什么意思/

    转自http://www.zybang.com/question/b158a106b4e39d8fdb2b93fd3777a00f.html 在基准电压的数据手册里,我们会找到一个描述基准性能的直流参 ...

  5. [2017BUAA软工]个人项目

    软工个人项目 一.Github项目地址 https://github.com/Lydia-yang/2017BUAA-SoftwareEngineering 二.解题思路 在刚开始拿到题目的时候,关于 ...

  6. Spring Cloud 路由网关服务端

    修改application.properties配置文件:服务端口号.本机名称: 启动注册中心:java -jar uap-register-server-1.0.jar --spring.confi ...

  7. Linux 下如何知道是否有人在使坏?

    在 Linux 下查看用户的行为,不仅仅是网管要做的事,也是开发人员所应该具备的基本技能之一.为什么呢?因为有时其他同事在做一些很消耗资源的事情,比如在编译大型程序,可能会导致服务器变得很慢,从而影响 ...

  8. lamp下mysql安全加固

    lamp下mysql安全加固 1.修改root用户口令,删除空口令 缺省安装的MySQL的root用户是空密码的,为了安全起见,必须修改为强密码,所谓的强密码,至少8位,由字母.数字和符号组成的不规律 ...

  9. linux_目录基本操作

    ls命令 ls命令用来显示目标列表,在Linux中是使用率较高的命令.ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件. 语法 $ ls [选项] [目录] 选项 说明 -a 显示所有档案 ...

  10. Qt__CMakeLists.txt

    cmake_minimum_required(VERSION 3.1.0) project (Project) if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FL ...