-
Notifications
You must be signed in to change notification settings - Fork 2
/
10061.cpp
89 lines (79 loc) · 1.17 KB
/
10061.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
#define maxn 1048579
char sv[maxn+2];
int N, B;
vector<int>P;
void Primetable() {
int i, j;
for(i = 2; i*i<maxn; ) {
for(j = i+i; j<= maxn; j+=i)
sv[j] = 1;
for(++i; sv[i]; i++);
}
P.push_back(2);
for(i = 3; i<maxn; i+=2)
if(sv[i] == 0)
P.push_back(i);
}
int times(int n) {
int i, sum = 0;
for(i = n; i<=N; i *= n)
sum += N/i;
return sum;
}
int Zeros() {
int i, k, n = B, zero = 2147483647, t, a, m;
for(i = 0; i<P.size() && n>1; i++) {
m = P[i];
m *= m;
if(m> n) break;
if(n % P[i] == 0) {
k = 0;
while(n % P[i] == 0) {
k ++;
n/= P[i];
}
t = times(P[i]);
a = t/k;
if(zero>a)
zero = a;
}
}
if(n>1)
t = times(n);
if(zero>t) zero = t;
return zero;
}
int digit() {
int i, dig;
double sum = 0;
for(i = 1; i<= N; i++)
sum += log10(i) / log10(B);
sum += 1e-5;
dig = ceil(sum);
return dig;
}
void Cal() {
int z, dig;
if(N == 0) {
cout<<"0 "<<"1\n";
return;
}
if(N == 1) {
cout<<"0 "<<"1\n";
return;
}
z = Zeros();
dig = digit();
cout<<z<<" "<<dig<<endl;
}
int main() {
Primetable();
while(cin>>N>>B) {
Cal();
}
return 0;
}