pat1015. Reversible Primes (20)
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 (< 105) 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
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
bool prime[];
void getprime(int n){
memset(prime,false,sizeof(prime));
int i,j;
prime[]=true;
for(i=;i<=n;i+=){
prime[i]=true;
for(j=;j*j<=i;j++){
if(i%j==){
prime[i]=false;
break;
}
}
}
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
getprime();
int n,d;
while(scanf("%d",&n)!=EOF){
if(n<){
break;
}
scanf("%d",&d);
if(!prime[n]){
printf("No\n");
continue;
}
queue<int> q;
while(n){
q.push(n%d);
n/=d;
}
//cout<<n<<endl;
while(!q.empty()){
n*=d;
n+=q.front();
q.pop();
}
//cout<<n<<endl;
if(prime[n]){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return ;
}
pat1015. Reversible Primes (20)的更多相关文章
- PAT-1015 Reversible Primes (20 分) 进制转换+质数
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- 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 (20分) 谜一般的题目,不就是个进制转换+素数判断
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 1015 Reversible Primes (20)(20 point(s))
problem A reversible prime in any number system is a prime whose "reverse" in that number ...
- 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 ...
- PAT Advanced 1015 Reversible Primes (20) [素数]
题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...
- 1015 Reversible Primes (20 分)
A reversible prime in any number system is a prime whose "reverse" in that number system i ...
- PAT1015. Reversible Primes
//题的理解是n在基数b中的的表示中,正序和逆序值都是素数,但是其实可直接判断n,因为n在b中的正常序列值就是再换成十进制就是n,但是不A:不知道为什么 用笨方法,先把n展开成b进制,正常计算其实是翻 ...
随机推荐
- Ubuntu16.04切换python3和python2
切换Python3为默认版本: sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo ...
- C# winform 打开新窗体 关闭当前窗体
Form1 的Button 下 { Form2 f2 = new Form2(); f2.ShowDialog(this);// this.Close(); } Form2 的load 下 { //只 ...
- SQL server T-SQL存储过程
简介 存储过程是由一些SQL语句和控制语句组成的被封装起来的过程,它驻留在数据库中,可以被客户应用程序调用,也可以从另一个过程或触发器调用.它的参数可以被传递和返回.与应用程序中的函数过程类似,存储过 ...
- Redis缓存穿透、缓存雪崩
缓存穿透 缓存穿透是指查询一个一定不存在的数据,由于缓存是不命中时被动写的,并且出于容错考虑,如果从存储层查不到数据则不写入缓存,这将导致这个不存在的数据每次请求都要到存储层去查询,失去了缓存的意义. ...
- angular 中间人模式
import { Component, OnInit, EventEmitter, Output } from '@angular/core'; @Component({ selector: 'app ...
- Selenium辅助工具
下载Firefox39.0版本浏览器,安装firebug和FirePath.最新版的Firefox在扩展组件中无法找到firebug,可以使用旧的版本的Firefox浏览器. FirePath插件的使 ...
- Android手机中怎么样在没root的情况下 修改 hosts 文件
工具 链接:https://pan.baidu.com/s/1AENluDCQ-2qYDPcE5K6l8g 密码:t7eu http://bbs.360.cn/forum.php?mod=view ...
- 「BZOJ1433」[ZJOI2009] 假期的宿舍(二分图,网络流)
题目描述 学校放假了 · · · · · · 有些同学回家了,而有些同学则有以前的好朋友来探访,那么住宿就是一个问题.比如 A 和 B 都是学校的学生,A 要回家,而 C 来看B,C 与 A 不认识. ...
- 虚拟机网络配置,桥接模式和NAT模式
虚拟机网络设置方式的研究: 主要就是桥接网络,和NAT模式: 桥接网络:桥接网络中,相当于虚拟机的网卡和主机的物理网卡均连接到虚拟机软件提供的VMnet0虚拟交换机上,因此虚拟机和主机是平等的,相当于 ...
- 【Thread】线程工厂-ThreadFactory
ThreadFactory---线程工厂 在apollo源码中有这么一段代码 ExecutorService m_longPollingService = Executors.newSingleThr ...