【PAT甲级】1015 Reversible Primes (20 分)
题意:
每次输入两个正整数N,D直到N是负数停止输入(N<1e5,1<D<=10),如果N是一个素数并且将N转化为D进制后逆转再转化为十进制后依然是个素数的话输出Yes,否则输出No。
trick:
判断转化后的数是不是1,1不是素数,如果转化后不是1说明转化前也不会是1(第一个测试点错误原因)。
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,d;
while(cin>>n){
if(n<)
break;
cin>>d;
int flag=;
for(int i=;i*i<=n;++i)
if(n%i==)
flag=;
int a[]={};
int cnt=;
while(n){
a[++cnt]=n%d;
n/=d;
}
int x=;
for(int i=;i<=cnt;++i){
x*=d;
x+=a[i];
}
if(x==)
flag=;
for(int i=;i*i<=x;++i)
if(x%i==)
flag=;
if(flag)
cout<<"No"<<"\n";
else
cout<<"Yes"<<"\n";
}
return ;
}
【PAT甲级】1015 Reversible Primes (20 分)的更多相关文章
- PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- 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(20)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 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 ...
- PAT 甲级 1015 Reversible Primes
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...
- PAT Advanced 1015 Reversible Primes (20) [素数]
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
随机推荐
- webRTC中回声消除(AEC)模块编译时aec_rdft.c文件报错:
webRTC中回声消除(AEC)模块编译时aec_rdft.c文件报错. 原因是: 局部变量ip跟全局变量冲突的问题,可以将局部变量重新命名一下,就可以通过编译了. aec_rdft.c修改以后文件代 ...
- tomcat服务器启动执行的两个方法
第一 SetApplicationContext(需要继承ApplicationContextAware)重写 第二 ContextInitialize(需要继承servleContet)重写,(co ...
- php常用函数归纳
php常用函数归纳: /** * 截取指定长度的字符 * @param type $string 内容 * @param type $start 开始 * @param type $length 长度 ...
- 5、Maven-构建配置文件
什么是构建配置文件? 配置文件是一组配置的集合,用来设置或者覆盖Maven构建的默认设置, 使用配置文件可以为不同的环境定制构建过程,例如Producation和Development环境. Prof ...
- websocket对象及方法
# websocket对象及方法 1.websocket对象 以下 API 用于创建 WebSocket 对象. var Socket = new WebSocket(url, [protocol] ...
- UVA10600 ACM Contest and Blackout
用prim算法求最小生成树和次小生成树~ #include<cstdio> #include<algorithm> #include<cstring> using ...
- EVE上传Dynamips、IOL和QEMU镜像
1.镜像保存目录: /opt/unetlab/addons ---/dynamips Dynamips镜像保存目录 ---/iol IOL镜像保存目录(运行IOU的镜像 ...
- 消息队列(四)--- RocketMQ-消息发送2
概述 接着我们上一篇继续分析消息发送,上节讲到消息发送前有可能遇到 broker 失效的情况,RocketMQ 主要是采用两种策略 : 重试发送 broker 故障延迟机制 后者指的是当发送给 ...
- JAVA8-用lamda表达式和增强版Comparator进行排序
1.单条件升序: list.sort(Comparator.comparing(User::getId); 2.降序: list.sort(Comparator.comparing(User::get ...
- Java AQS 的胡言乱语修正版
前言 适合读者:3 年以上经验的同学 谈到并发编程,基本上都会想到JDK 的 JUC 工具包,它包含 锁,并发工具类,原子类,线程池,还有阻塞队列,这是从网上找的一个大致的知识体系. 相信这些工具读者 ...