zju pat 1015

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;
}
zju pat 1015

zju pat 1015

上一篇:VB6 red write DB using Microsoft DAO 3.6 Object Library


下一篇:01_turtle_海龟画图的移动和转向