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
#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的更多相关文章

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

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

  2. pat 1015 Reversible Primes(20 分)

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

  3. PAT 1015 Reversible Primes (判断素数)

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

  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 分) 凌宸1642

    PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any n ...

  6. PAT 甲级 1015 Reversible Primes(20)

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

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

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

  8. PTA (Advanced Level) 1015 Reversible Primes

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

  9. PAT 甲级 1015 Reversible Primes

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

随机推荐

  1. 集成算法——Ensemble learning

    目的:让机器学习效果更好,单个不行,群殴啊! Bagging:训练多个分类器取平均 Boosting:从弱学习器开始加强,通过加权来进行训练 (加入一棵树,比原来要强) Stacking:聚合多个分类 ...

  2. css display属性

    C:内联元素加上display:block后被块级化.块级元素一般是其他元素的容器,可容纳内联元素和其他块状元素,块级元素排斥其他元素与其位于同一行,width和height起作用.因此,可以定义其宽 ...

  3. Unity--game

    打怪兽--头像状态 Git :https://github.com/vinieo/attck 打怪兽--背景音乐音量 Git :https://github.com/vinieo/ack_bgm 小球 ...

  4. RedHat(Linux)下安装Python3步骤

    1. 下载解压.$ wget https://www.python.org/ftp/python/3.4.1/Python-3.4.1.tgz$ tar zxvf Python-3.4.1.tgz 2 ...

  5. maven 引入外部jar包的几种方式

    方式1:dependency 本地jar包 <dependency> <groupId>com.hope.cloud</groupId> <!--自定义--& ...

  6. SpringBoot之profile的使用

    Profile配置是针对不同的环境提供不同的配置支持,比如,在开发环境的配置和测试环境下的配置不同,那么就可以使用Profile配置来实现该要求. 在你的src/main/resources下建立相应 ...

  7. 从classloader的变更说起

    classloader从1.6到1.7整体分成了两个版本.重点区别就是并行类加载. 1.6版本 protected synchronized Class loadClass(String name, ...

  8. java与js交互,相互调用传参

    随着前端技术的发展与H5的广泛使用,移动端采用native+h5的方式越来越多了,对于Android来说就涉及到java与js的交互,相互调用传参等.下面就来看一下java与js交互的简单demo. ...

  9. Wannafly挑战赛19 B矩阵

    矩阵 思路: 预处理好前缀和,枚举上边界和下边界,将二维变成一维,用单调队列找满足题意的最小前缀 复杂度,O(r*r*c) 代码: #pragma GCC optimize(2) #pragma GC ...

  10. (转)c# 断言类

    Assert 类 使用 true/false 命题验证单元测试中的条件. 继承层次结构 System.Object Microsoft.VisualStudio.TestTools.UnitTesti ...