P1069. 细胞分裂

考点

  • 算术基本定理

题解

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
#include <bits/stdc++.h>
using namespace std;
const int LEN = 1e6 + 50;
int m1, m2, tot, pri[LEN], cnt[LEN];

// 分解质因数
void f() {
for (int i = 2; i <= m1 / i; ++i) {
if (m1 % i == 0) {
pri[++tot] = i;
while (m1 % i == 0) ++cnt[i], m1 /= i;
}
}
if (m1 > 1) ++cnt[m1], pri[++tot] = m1;
}

int main() {
int n, s, ans = 0x3f3f3f3f;
cin >> n >> m1 >> m2, f();
while (n--) {
cin >> s;
// m1 == 1时的特殊情况,此时没有质数
// 但此时x完全可以取0
int x = 0;
for (int i = 1; i <= tot; ++i) {
int num = 0, p = pri[i];
if (s % p) {
x = -1;
break;
}
while (s % p == 0) {
++num, s /= p;
}
x = max(x, (cnt[p] * m2 - 1) / num + 1);
}
if (~x) ans = min(ans, x);
}
ans == 0x3f3f3f3f ? cout << -1 : cout << ans;
return 0;
}

思路

《深基》的教学题,直接上图