关闭

1015. Reversible Primes (20)

161人阅读 评论(0) 收藏 举报
分类:

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 <bits/stdc++.h>
using namespace std;
bool isprime(int n){
    if(n<2)
        return false;
    for(int i=2;i*i<=n;++i){
        if(n%i==0)
            return false;
    }
    return true;
}
int convert(int num,int radix){
    int m=0;
    while(num){
        m=m*radix+num%radix;
        num/=radix;
    }
    return m;
}
int main(){
    int n,radix;
    while(cin>>n&&n>=0){
        cin>>radix;
        if(isprime(n)&&isprime(convert(n,radix)))
            puts("Yes");
        else puts("No");
    }
}
0
0
查看评论

[PAT (Advanced Level) ]1015. Reversible Primes 解题文档

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime...
  • u010536377
  • u010536377
  • 2015-10-12 20:32
  • 291

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 decim...
  • zjujqq
  • zjujqq
  • 2013-08-29 10:50
  • 501

PAT_A 1015. Reversible Primes (20)

反转素数
  • scylhy
  • scylhy
  • 2017-01-30 10:22
  • 195

1015. Reversible Primes (20) 进制转换

#include #include #include #include #include #include #include #include #include #include using namespace std; #define INF 0x6fffffff bool isPrime(int...
  • li_jie0919
  • li_jie0919
  • 2015-10-01 14:42
  • 124

【PAT】1015. Reversible Primes (20)

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1015 题目不难,就是表述不清楚,看的费劲。 题目的意思是:给出一个数N和一个基数D。首先这个数必须是素数。其次,将这个数(1)转为D进制数(2)将这个D进制数反转(3)将反转后的数再转为十进制数,这...
  • realxuejin
  • realxuejin
  • 2013-08-21 15:33
  • 1651

PAT 1015. Reversible Primes (20)

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A reversible prime...
  • u010069101
  • u010069101
  • 2014-03-15 12:07
  • 414

PAT-A 1015. Reversible Primes (20)

给出正整数N进制Radix,若N是素数,且N在Radix进制下反转后的数在十进制下也是素数,则输出Yes,否则输出No。
  • Daniel960601
  • Daniel960601
  • 2017-03-29 19:07
  • 162

1015. Reversible Primes (20)-PAT

1015. Reversible Primes (20) A reversible prime in any number system is a prime whose "reverse" in that number system is also a ...
  • zoushidexing
  • zoushidexing
  • 2013-07-18 10:12
  • 899

pat 1015. Reversible Primes (20)

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue...
  • wyh7280
  • wyh7280
  • 2015-07-23 01:01
  • 336

PAT_A 1015. Reversible Primes (20)

1015. Reversible Primes (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue...
  • todoooooo
  • todoooooo
  • 2018-02-02 22:38
  • 10
    个人资料
    • 访问:132806次
    • 积分:4908
    • 等级:
    • 排名:第6942名
    • 原创:371篇
    • 转载:9篇
    • 译文:0篇
    • 评论:39条
    博客专栏
    最新评论