题意:

每次输入两个正整数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 分)的更多相关文章

  1. PAT 甲级 1015 Reversible Primes (20 分) (进制转换和素数判断(错因为忘了=))

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

  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(20)

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

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

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

  5. 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 ...

  6. PAT 甲级 1015 Reversible Primes

    https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...

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

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

  8. 1015 Reversible Primes (20 分)

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

  9. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

随机推荐

  1. JEECG屏蔽在线聊天插件

    如图所示: 找到pom.xml文件将如下代码屏蔽即可: <!-- 在线聊天工具 --> <dependency> <groupId>org.p3framework& ...

  2. Dart语言学习(八) dynamic

    dynamic 表示是动态的,数据类型是指任意类型 var a; a = ; a = "Dart"; print(a); dynamic b = ; b = "JavaS ...

  3. 解决maven项目java中配置文件打包被忽略

    pom.xml中添加以下配置 <build> <!--配置打包时不过滤非java文件开始 --> <!--说明,在进行模块化开发打jar包时,maven会将非java文件 ...

  4. hybird怎么实现的(核心webview)

    链接:https://blog.csdn.net/gongch0604/article/details/80510005

  5. 城市间紧急救援 Dijkstra

    作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两个城市的快速道路长度都标在地图上.当其他城市有紧急求 ...

  6. Java JDK 1.5 1.6 1.7 新特性整理

    Java JDK 1.5的新特性 1.泛型 List<String> strs = new ArrayList<String>();//给集合指定存入类型,上面这个集合在存入数 ...

  7. js正则验证表达式验证

    /* 合法uri */ export function validateURL(textval) {  const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\ ...

  8. A. Angry Students

    网址:http://codeforces.com/problemset/problem/1287/A It's a walking tour day in SIS.Winter, so tt grou ...

  9. 支付接口API

    //微信支付SDK https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1

  10. 【译】高级T-SQL进阶系列 (三)【中篇】:理解公共表表达式(CTEs)

    [译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 一个简单的CTE例子 如前所述,CTE‘s提供给你了一个方法来更容易的书写复杂的代码以提高其可读性.假设你有列表 ...