-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1024.cpp
More file actions
94 lines (90 loc) · 2.02 KB
/
1024.cpp
File metadata and controls
94 lines (90 loc) · 2.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
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
90
91
92
93
94
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define inf HUGE_VAL
#define mem(a, b) memset(a, b, sizeof(a))
bool pr[106];
vector<int> prim;
int mx;
int fact[10001];
void sieve(int n) {
memset(pr, 0, sizeof(pr));
long i, j, k, l;
pr[1] = 1;
prim.push_back(2);
for (i = 4; i <= n; i += 2) pr[i] = 1;
for (i = 3; i <= n; i += 2) {
if (pr[i] == 0) {
prim.push_back(i);
for (j = i * i; j <= n; j += 2 * i) pr[j] = 1;
}
}
}
void factor(int n) {
int i, j, count;
for (j = 0; j < prim.size() && prim[j] * prim[j] <= n; j++) {
i = prim[j];
count = 0;
if (n % i == 0) {
mx = max(i, mx);
}
while (n % i == 0) {
n /= i;
count++;
}
fact[i] = max(fact[i], count);
if (n == 1) break;
}
if (n > 1) {
mx = max(n, mx);
fact[n] = max(fact[n], 1);
}
}
string s;
void mult(int n, int r) {
while (r--) {
int k, i, carry = 0;
for (i = 0; i < s.size(); i++) {
k = s[i] - '0';
k = (n * k) + carry;
s[i] = k % 10 + '0';
carry = k / 10;
}
while (carry > 0) {
s += carry % 10 + '0';
carry /= 10;
}
}
}
int main() {
sieve(101);
int n, k, i, m, c;
int tc, t = 1;
scanf("%d", &tc);
while (tc--) {
scanf("%d", &n);
mem(fact, 0);
mx = -inf;
while (n--) {
scanf("%d", &k);
factor(k);
}
s = "1";
for (i = 2; i <= mx; i++) {
if (fact[i]) {
mult(i, fact[i]);
}
}
reverse(s.begin(), s.end());
printf("Case %d: %s\n", t++, s.c_str());
}
return 0;
}