PAT 甲级 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 分) (进制转换和素数判断(错因为忘了=))的更多相关文章
- PAT-1015 Reversible Primes (20 分) 进制转换+质数
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...
- PAT 1015 Reversible Primes[求d进制下的逆][简单]
1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...
- PAT 甲级 1015 Reversible Primes(20)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- PAT Advanced 1015 Reversible Primes (20) [素数]
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 【PAT甲级】1015 Reversible Primes (20 分)
题意: 每次输入两个正整数N,D直到N是负数停止输入(N<1e5,1<D<=10),如果N是一个素数并且将N转化为D进制后逆转再转化为十进制后依然是个素数的话输出Yes,否则输出No ...
- 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 ...
- 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
随机推荐
- 解决pynq联网问题
注:本文只在一种环境下实验!不一定能适用很多环境 一.由于校园网的限制,pynq之间连接路由器存在无法联网的情况! 因此本文主要针对需要登录认证问题提供一种解决方案: 网络环境:校园网络 网络登录:锐 ...
- 深入理解Kubernetes资源限制:CPU
写在前面 在上一篇关于Kubernetes资源限制的文章我们讨论了如何通过ResourceRequirements设置Pod中容器内存限制,以及容器运行时是如何利用Linux Cgroups实现这些限 ...
- 用Python做一个飞机大战游戏
基于pygame的一款小游戏 这是我上半年做的一款小游戏,但是一直忘记了,现在才上传代码. github项目地址:StarMan 代码基于pygame,Python版本3.5.2运行正常. 游戏很简单 ...
- Android.mk走读与Cmake配置
Android.mk认识: 在上一次[https://www.cnblogs.com/webor2006/p/9946061.html]中学会了用NDK提供的交叉编译工程编译成Android能运行的可 ...
- mysql中对表操作----为所有列插入数据
为所有列插入数据 通常情况下,向数据表中插入数据应包含表中所有字段,也就是为表中所有字段添加数据,为表中所有字段添加数据有以下两种方式. 1.INSERT语句中指定所有字段名 使用INSER ...
- exception about Kernel Panic // dirperm1 breaks the protection by the permission bits on the lower branch
问题描述: 1. K8S集群有一个worker,经常磁盘满,然后导致服务异常. 2. 查看/var/log/syslog, 发现非常多的异常如下: 1568405.455565] docker0: p ...
- 前端面试题-HTML+CSS
引用GitHub 上 ltadpoles的前端面试 https://github.com/ltadpoles HTML部分 1. Doctype作用,HTML5 为什么只需要写<!DOCTYPE ...
- python自动华 (十一)
Python自动化 [第十一篇]:Python进阶-RabbitMQ队列/Memcached/Redis 本节内容: RabbitMQ队列 Memcached Redis 1. RabbitMQ ...
- 011_Linux驱动之_s3c2410_gpio_getpin
1. 功能:获取引脚状态 2. 函数原型: unsigned int s3c2410_gpio_getpin(unsigned int pin) { void __iomem *base = S3C2 ...
- FTPClient上传下载等
package com.lct.conference.controller.MonitorManagement.cofer; import org.apache.commons.net.ftp.FTP ...