-
Notifications
You must be signed in to change notification settings - Fork 0
/
UvA 160.cpp
75 lines (53 loc) · 1.27 KB
/
UvA 160.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
75
#include <bits/stdc++.h>
#define pb push_back
#define lp(i,n) for(int i=0; i<n; i++)
#define lli long long int
using namespace std;
int primearr[10000];
void gen_prime(){
primearr[1]=1;
primearr[0]=1;
for(int i=0; i*i<=10000; i++){
if(primearr[i]==0){
for(int j=i+i; j<=10000; j+=i){
primearr[j]=1;
}
}
}
}
long long int Max_power_N (long long int n,long long int p){
int ans=0;
for(int i=p; i<=n; i*=p){
ans+=n/i;
}
return ans;
}
vector <pair <int, int>> Factor_N(int n){
vector <pair <int, int>> ans;
for(int i=0; i<=n; i++){
if(primearr[i]==0){
ans.pb(make_pair(i,Max_power_N(n,i)));
}
}
return ans;
}
int main(){
gen_prime();
int n;
cin>>n;
while(n!=0){
vector <pair <int, int>> factors =Factor_N(n);
printf("%3d! =",n);
int cnt=0;
for(int i=0; i<factors.size(); i++){
printf("%3d",factors[i].second);
cnt++;
if(cnt==15 && i!=factors.size()-1){
cnt=0;
printf("\n ");
}
}
cout<<endl;
cin>>n;
}
}