1015 Reversible Primes (20)(20 point(s))
problem
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 (< 10^5^) and D (1 < D <= 10), 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
answer
#include<bits/stdc++.h>
using namespace std;
int prime[100000] = {2, 3};
set<int> s;
void Prime(){
s.insert(2);
s.insert(3);
int i, j, flag, ta = 2;
for(i = 5; i < 100010; i+=2){
for(j = 0, flag = 1; prime[j]*prime[j] <= i; j ++){
if(i % prime[j] == 0) {
flag = 0; break;
}
}
if(flag){
prime[ta++] = i;
s.insert(i);
}
}
}
bool isPrime(int num)
{
set<int>::iterator it;
it = s.find(num);
if(it != s.end()) return true;
else return false;
}
int Reverse(int a, int d){
vector<int > s;
while(a > 0){
s.push_back(a%d);
a/=d;
}
int num = 0;
reverse(s.begin(), s.end());
for(int i =0; i< s.size(); i++){
num += s[i]*pow((float)d, i);
// cout<<s[i];
}
return num;
}
int main(){
ios::sync_with_stdio(false);
// freopen("test.txt", "r", stdin);
Prime();
int N, M;
while (cin>>N){
if(N < 0) break;
cin>>M;
if(!isPrime(N) || !isPrime(Reverse(N,M))) {
cout<<"No"<<endl;
}else{
cout<<"Yes"<<endl;
}
}
return 0;
}
experience
- 素数晒法,背下模板。
1015 Reversible Primes (20)(20 point(s))的更多相关文章
- 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 "reverse& ...
- 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
1015 Reversible Primes (20 分) A reversible prime in any number system is a prime whose "rever ...
- PAT 1015 Reversible Primes[求d进制下的逆][简单]
1015 Reversible Primes (20)(20 分)提问 A reversible prime in any number system is a prime whose "r ...
- PAT 甲级 1011 World Cup Betting (20)(20 分)
1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...
- PAT 甲级 1001 A+B Format (20)(20 分)
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
- PAT 1049 数列的片段和(20)(代码+思路分析)
1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...
- PAT 1033 旧键盘打字(20)(20 分)
1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...
随机推荐
- BZOJ4819 新生舞会
4819: [Sdoi2017]新生舞会 Time Limit: 10 Sec Memory Limit: 128 MB Description 学校组织了一次新生舞会,Cathy作为经验丰富的老学 ...
- C 语言中指针初始化为字符串常量 不可通过该指针修改其内容
char b[] = "hello"; 则“hello”存于栈中,因为定义的是一个数组. char *b = "hello"; 则"hello&quo ...
- python基础——python解析yaml类型文件
一.yaml介绍 yaml全称Yet Another Markup Language(另一种标记语言).采用yaml作为配置文件,文件看起来直观.简洁.方便理解.yaml文件可以解析字典.列表和一些基 ...
- A - ACM Computer Factory(网络流)
题目链接:https://cn.vjudge.net/contest/68128#problem/A 反思:注意拆点,否则的话节点就没用了,还有注意源点和汇点的赋值. AC代码: #include&l ...
- 利用phpMyAdmin提权
利用phpMyAdmin提权 发表于 2016-03-31 | 分类于 phpMyAdmin | 暂无评论 | 9次阅读 爆路径 /phpmyadmin/libraries/lec ...
- PHP简单爬虫 爬取免费代理ip 一万条
目标站:http://www.xicidaili.com/ 代码: <?php require 'lib/phpQuery.php'; require 'lib/QueryList.php'; ...
- 洛谷 P4559: bzoj 5319: [JSOI2018]军训列队
题目传送门:洛谷 P4559. 题意简述: 有 \(n\) 个学生,编号为 \(i\) 的学生有一个位置 \(a_i\). 有 \(m\) 个询问,每次询问编号在 \([l,r]\) 区间内的学生跑到 ...
- Linux设备驱动程序学习 高级字符驱动程序操作[阻塞型I/O和非阻塞I/O]【转】
转自:http://blog.csdn.net/jacobywu/article/details/7475432 阻塞型I/O和非阻塞I/O 阻塞:休眠 非阻塞:异步通知 一 休眠 安全地进入休眠的两 ...
- Linux学习笔记-文件系统和基本命令
目录 分区设备文件名 分区 挂载 文件目录 文件处理命令 目录处理命令 硬件设备文件名 IDE硬盘 /dev/hd[a-d] USB硬盘 /dev/sd[a-p] 光驱 /dev/cdrom或者/de ...
- 07 go语言
Home Alexey Palazhchenko edited this page on 9 Jul · 89 revisions Welcome to the Go wiki, a collec ...