1015. Reversible Primes (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

  1. PAT-1015 Reversible Primes (20 分) 进制转换+质数

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

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

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

  3. PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642

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

  4. PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  5. 1015 Reversible Primes (20)(20 point(s))

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

  6. 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 ...

  7. PAT Advanced 1015 Reversible Primes (20) [素数]

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  8. 1015 Reversible Primes (20 分)

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

  9. PAT1015. Reversible Primes

    //题的理解是n在基数b中的的表示中,正序和逆序值都是素数,但是其实可直接判断n,因为n在b中的正常序列值就是再换成十进制就是n,但是不A:不知道为什么 用笨方法,先把n展开成b进制,正常计算其实是翻 ...

随机推荐

  1. 读写文本文件之StreamReader和StreamWriter

    private string _filePath = @"1.txt"; //查询文件是否存在,如果不存在,则创建 if (!File.Exists(_filePath)) { u ...

  2. 导出当前python安装了哪些第三方模块+批量安装python模块

    pip freeze > mokuai.txt  #导出你当前python环境里面有哪写第三方模块 pip install -r mokuai.txt #从文件里面批量安装模块

  3. MySQL 学习笔记(二):数据库更新、视图和数据控制

    基础准备: 在 school 数据库下建立student.course.sc 三个表: create table student( Sno ) primary key, Sname ) unique, ...

  4. MySQL学习笔记(一):查询

    查询实例: 1.创建数据库并使用: create database school; use school; 2.创建表并插入内容: create table student( Sno char(9) ...

  5. 题解 P4140 【奇数国 】

    题目链接 首先,按照题意,把前$60$个素数打出来$[2$ $-$ $281]$. 因为只有$60$个,再加上本宝宝极其懒得写线性筛于是每一个都$O(\sqrt{n})$暴力筛就好了. 代码如下: # ...

  6. 洛谷P4014 分配问题(费用流)

    传送门 可以把原图看做一个二分图,人在左边,任务在右边,求一个带权的最大和最小完美匹配 然而我并不会二分图做法,所以只好直接用费用流套进去,求一个最小费用最大流和最大费用最大流即可 //minamot ...

  7. SDUT OJ 数据结构实验之链表四:有序链表的归并

    数据结构实验之链表四:有序链表的归并 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Desc ...

  8. 对KMP算法通过代码生成next数组理解

    本文是根据考研数据结构2019版天勤高分笔记理解编写的: 首先给出代码: 1 void getnext(Str substr,int next[]){ 2 int i=0,j=0; 3 next[1] ...

  9. SDK,JDk,Unity打包安卓apk

    SDK:软件开发工具包(缩写:SDK.外语全称:Software Development Kit)一般都是一些软件工程师为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件时的开发工具的集合. ...

  10. 215 Kth Largest Element in an Array 快排

    题目:在无序的数组中找到第k大的元素,也就是若长度为n的数组从小到大排列时,下标为n-k的元素. 注意Example2:第4大的元素是4,也就是数组中出现的两个5分别是第2大和第3大的数字. 解法一: ...