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 ...
随机推荐
- [ajaxupload] - 上传文件同时附件参数值
$.ajax({ url: '/excel/importExcel?instance='+"品种1", type: 'POST', data: formData, 上面前端通过?拼 ...
- HihoCoder 1195 高斯消元·一(高斯消元)
题意 https://hihocoder.com/problemset/problem/1195 思路 高斯消元是解决高元方程的一种算法,复杂度 \(O(n^3)\) . 过程大致是: 构造一个未知数 ...
- 使用Numpy实现卷积神经网络(CNN)
import numpy as np import sys def conv_(img, conv_filter): filter_size = conv_filter.shape[1] result ...
- Docker6之Network containers
how to network your containers. Launch a container on the default network Docker includes support fo ...
- Ajax - 汇总
1,什么是ajax? 为什么要使用ajax? 1.ajax是"asynchornous javascript and xml "的缩写,指一种创建交互式网页应用的网页开发技术. 2 ...
- 如何用conda安装软件|处理conda安装工具的动态库问题
conda的确是一个非常好的工具,对于初学者而言,安装软件就跟用XXX软件管理器一样方便.正因为他如此便利,以至于我介绍如何手动安装工具时,总有人问我为啥不用conda. 我用conda,并且用的很好 ...
- vue自定义错误界面
方案一: 当输入错误链接错误或者找不到页面,在router里可以定义一个404页面,具体可以这样做:在routes里面这样写: { path:'*', component:error, name:'e ...
- Eclipse中使用MySql遇到:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading o
在Eclipse中使用MySQL遇到了点小问题 如果对Eclipse中配置MySql还有疑问的可以参考一下这篇博客:https://blog.csdn.net/qq_38247544/article/ ...
- leecode第二十六题(删除排序数组中的重复项)
class Solution { public: int removeDuplicates(vector<int>& nums) { int len=nums.size(); ) ...
- eclipse中怎么调出左边项目列表,解决方法:主界面的最上面一栏的Window--ShowView--Project Explorer
主界面的最上面一栏的Window--ShowView--Project Explorer