标签:zju-pat
#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
原文地址:http://blog.csdn.net/happy_cheng/article/details/43940987