-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path10139.cpp
More file actions
97 lines (95 loc) · 1.21 KB
/
10139.cpp
File metadata and controls
97 lines (95 loc) · 1.21 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<stdio.h>
#include<math.h>
#include<map>
using namespace std;
#define si 50020
map<int,int>mp;
int ara[si],pr[si],ll=1,store[si];
void sieve()
{
int num=si-5,i,j,root;
root=sqrt(num);
ara[0]=ara[1]=1;
pr[ll++]=2;
for(i=3;i<=num;i=i+2)
{
if(ara[i]==0)
{
pr[ll++]=i;
if(i<=root)
{
for(j=i*i;j<=num;j+=2*i)
ara[j]=1;
}
}
}
}
int main()
{
int i,n,j,l,m,a,b,fg,x,cnt,k;
sieve();
while(~scanf("%d%d",&n,&a))
{
if(n>=a&&a)
{
printf("%d divides %d!\n",a,n);
continue;
}
else if(!a)
{
printf("%d does not divide %d!\n",a,n);
continue;
}
j=1;
l=sqrt(a)+1;
x=a;
for(i=1;pr[i]<=l&&i<ll;i++)
{
if(x%pr[i]==0)
{
cnt=0;
while(x%pr[i]==0)
{
x/=pr[i];
cnt++;
}
store[j++]=pr[i];
mp[pr[i]]=cnt;
}
if(x==1)
break;
}
if(x>1)
{
store[j++]=x;
mp[x]=1;
}
fg=1;
for(i=1;i<j;i++)
{
k=1;
cnt=0;
while(1)
{
x=pow(store[i],k);
m=n/x;
if(m==0)
break;
cnt+=m;
if(cnt>=mp[store[i]])
break;
k++;
}
if(cnt<mp[store[i]])
{
fg=0;
break;
}
}
if(fg)
printf("%d divides %d!\n",a,n);
else
printf("%d does not divide %d!\n",a,n);
}
return 0;
}