zju pat 1015

#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;

bool prime(int num)
{
    int i;
    if(num ==0 || num ==1)
        return false;
    for(i=2;i<=sqrt(double(num));i++)
    {
        if(num % i ==0)
            return false;
    }
    return true;
}

int convert(int n,int d)
{
    int sum =0;
    while(n!=0)
    {
        sum = sum*d + n %d;
        n = n/d;
    }
    return sum;
}

int main()
{
    int n,d;
    while(cin>>n)
    {
        if(n<0)
            break;
        cin>>d;
        if(prime(n) && prime(convert(n,d)))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

时间: 2024-10-27 06:07:01

zju pat 1015的相关文章

PAT——1015. 德才论

宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人." 现给出一批考生的德才分数,请根据司马光的理论给出录取排名. 输入格式: 输入第1行给出3个正整数,分别为:N(<=105),即考生总数:L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取:H(<100),为优先录取线

PAT 1015 Reversible Primes[求d进制下的逆][简单]

1015 Reversible Primes (20)(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

pat 1015 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 a

PAT 1015. Reversible Primes

#include <cstdio> #include <cstdlib> #include <cstring> #include <vector> using namespace std; void init_primes(vector<char>& primes) { int len = primes.size(); for (int i=0; i<len && i<2; i++) primes[i] = f

ZJU PAT 1090

依题意构造树并遍历,找出最大深度并统计 #include <iostream> #include <vector> using namespace std; struct Node { vector<int> children; int depth; }; Node nodes[100005]; int maxDepth = 0; int total = 1; void travel(int n, int d) { Node& node = nodes[n];

ZJU PAT 1091

如果直接使用递归,会因为递归层数过多导致段错误 因此使用queue代替递归 //递归调用层数过多,使用queue代替 #include <iostream> #include <vector> #include <queue> using namespace std; struct Point { int z, x, y; Point(int z, int x, int y) : z(z), x(x), y(y) {} }; int main() { int m, n,

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 (&

1015. Reversible Primes (20) ——PAT (Advanced Level) Practise

题目信息: 1015. Reversible Primes (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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

PAT Basic 1015

1015 德才论 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人." 现给出一批考生的德才分数,请根据司马光的理论给出录取排名. 输入格式: 输入第1行给出3个正整数,分别为:N(<=10^5^),即考生总数:L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取:H(<