PAT 1015 Reversible Primes
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 bool check[maxnum];
int prime[maxnum] = {}; void isprime(){
int cnt = ;
memset(check,true,sizeof(check));
for(int i=;i < maxnum;i++){
if(check[i])prime[++cnt] = i;
for(int j=;j <= cnt;j++){
if(i*prime[j] > maxnum)break;
check[i*prime[j]] = false;
if(i%prime[j] == )break;
}
}
} int main(){
int a,b;
isprime();
check[] = false;
check[] = false; // for(int i=0;i < 1000;i++){
// cout << check[i] << " ";
// }
while(scanf("%d",&a)){
if(a < ) break;
scanf("%d",&b);
vector<int> vec;
int t = a;
while(a){
vec.push_back(a%b);
a = a/b;
}
int sum = ;
int cnt = ;
for(int i=vec.size()-;i >= ;i--){
sum += cnt*vec[i];
cnt *= b;
}
if(check[sum]&&check[t]) cout << "Yes" << endl;
else cout << "No" << endl;
}
return ;
}
复习欧拉筛
PAT 1015 Reversible Primes的更多相关文章
- 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 1015 Reversible Primes (判断素数)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- 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 分) 凌宸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 分) (进制转换和素数判断(错因为忘了=))
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- PTA (Advanced Level) 1015 Reversible Primes
Reversible Primes A reversible prime in any number system is a prime whose "reverse" in th ...
- PAT 甲级 1015 Reversible Primes
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000 A reversible prime in ...
随机推荐
- 第五个神奇的电梯(代码抢先看<1>)
关于一些自认为比较独特的设计思路,也不知道是好还是坏,放在这里让大家一起看一下. 关于mian函数:因为采用了注册机制所以主函数比较简单. #include "stdafx.h" ...
- 【Ruby】【高级编程】正则
#[[正则]]=beginsub 和 gsub 及它们的替代变量 sub! 和 gsub! 是使用正则表达式时重要的字符串方法.所有这些方法都是使用正则表达式模式执行搜索与替换操作.sub 和 sub ...
- IOS学习笔记一1
//创建.h文件 界面的类文件(创建一个类) @interface MyClass:NSObject{ //类变量声明 int a; int b; } //类属性声明 (int) p2 //类方法声明 ...
- android studio 的基本使用和建立一个小项目
https://github.com/allenxieyusheng/Android-Studio
- 【BZOJ】1875: [SDOI2009]HH去散步
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1875 注意的是路径不可以重复,所以这题把边看成点.每一条无向边拆成两条有向边. 令${F[ ...
- 再谈java编码
一篇好文:从原理上搞懂编码——究竟什么是编码?什么是解码?什么是字节流? encode,即把字符按照指定的<编码gbk utf-8等>编码成该<编码>所表示的字节 decode ...
- java开发手册(阿里巴巴)——编程规约(部分)
(一)命名风格 3. [强制]类名使用 UpperCamelCase 风格,但以下情形例外:DO / BO / DTO / VO / AO / PO / UID 等. 正例:MarcoPolo / U ...
- 浅谈 Java JPDA
前言 程序员在坊间有非常多有趣的故事,其中就有这么一则:”这个在我的电脑上是好的,没问题的呀,诺,你看咯,一定是你打开姿势不正确,浏览器版本不正确,操作系统不统一等,总之不是我代码问题(傲娇)”.看到 ...
- arcface和Dlib人脸识别算法对比
我司最近要做和人脸识别相关的产品,原来使用的是其他的在线平台,识别率和识别速度很满意,但是随着量起来的话,成本也是越来越不能接受(目前该功能我们是免费给用户使用的),而且一旦我们的设备掉线了就无法使用 ...
- python + lisp hy的新手注记1
想在python里用lisp方言hy的目的: 1 用lisp去parse 包含 “数据+简单if控制流(代码.AST)”的配置文件,或者说用包含s-exp的.hy文件作为这类配置文件的实现(而不是用y ...