-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA1015.cpp
More file actions
69 lines (67 loc) · 1.04 KB
/
A1015.cpp
File metadata and controls
69 lines (67 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
using namespace std;
bool judge(int n)
{
int i;
if(n<=1)
return false;
else
{
for(i=2;i<n;i++)
{
if(n%i==0)
return false;
}
return true;
}
}
int tran(int a,int b)
{
vector<int> vec;
int t,i,r=a,s,ou=0;
int z,v;
while(r)
{
t=r%b;
r=r/b;
vec.push_back(t);
}
s=vec.size();
s--;
for(i=0;s>=0;s--,i++)
{
z=pow(b,i);
v=vec[s];
ou=ou+v*z;
}
return ou;
}
int main()
{
int a=0,b,t,n,i;
vector<int> s,z;
while(1)
{
cin>>a;
if(a<0) break;
cin>>b;
if(b<0) break;
s.push_back(a);
z.push_back(b);
}
n=s.size();
bool* j=new bool[n];
for(i=0;i<n;i++)
j[i]=judge(s[i])&&judge(tran(s[i],z[i]));
for(i=0;i<n;i++)
{
if(j[i])
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
delete []j;
return 0;
}