-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Factorial_Problem.cpp
More file actions
50 lines (47 loc) · 1.02 KB
/
Copy pathA_Factorial_Problem.cpp
File metadata and controls
50 lines (47 loc) · 1.02 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
/*
* @Date : 2020-05-28 16:19:38
* @Author : Abhimanyu Kumar Maurya (aerma7309@gmail.com)
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool ib = ios_base::sync_with_stdio(0);
bool it = cin.tie(0);
signed main()
{
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
map<int, int> n_factor, k_factor;
int j = 2, num = k;
while (j * j <= num)
{
while (num % j == 0)
{
k_factor[j]++;
num /= j;
}
j++;
}
if (num > 1)
k_factor[num]++;
for (auto &i : k_factor)
{
int j = 0, p = i.first;
while (p <= n)
{
j += n / p;
p *= i.first;
}
n_factor[i.first] = j;
}
int res = INT_MAX;
for (auto &i : k_factor)
res = min(res, n_factor[i.first] / i.second);
cout << res << '\n';
}
return 0;
}