forked from taraqr9/UVA-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva 10139 Factovisors.cpp
74 lines (69 loc) · 1.5 KB
/
uva 10139 Factovisors.cpp
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
#include <bits/stdc++.h>
#define i64 long long
i64 global;
i64 get_powers(i64 n, i64 p)
{
i64 res = 0;
for (i64 power = p ; power <= n ; power *= p)
res += n/power;
return res;
}
i64 prime[1000];
void prime_factor(i64 n)
{
i64 i,j=0;
// print the number of 2s that divide n
while(n%2==0){
prime[j++]=2;
n/=2;
}
// n must be odd at this point . So we can skip one element ( i.e = i+=2)
for(i=3;i*i<=n;i+=2){
while(n%i==0){
prime[j++]=i;
n/=i;
}
}
// at this point if n is greater than 2 than n itself is a prime factor
if(n>2)
prime[j++]=n;
global = j;
// printing the prime factors
// for(i=0;i<j;i++)
// printf("%d\n",prime[i]);
}
int main()
{
i64 n , m ,i ,check,count;
while(scanf("%lld %lld",&n,&m) == 2){
if ( m==1 )
printf("%lld divides %lld!\n",m,n);
else if(m!=0){
prime_factor(m);
i64 a = 0;
while(a<global){
count = 0;
for( i=0 ;i<global ; i++){
if(prime[i]==prime[a])
count ++;
}
if(get_powers(n, prime[a])>=count)
check= 1;
else{
check = 0 ;
break;
}
a++;
}
if(check==1)
printf("%lld divides %lld!\n",m,n);
else
printf("%lld does not divide %lld!\n",m,n);
}
// else if(m>n)
//
else
printf("%lld does not divide %lld!\n",m,n);
}
return 0;
}