forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjackpot.cpp
68 lines (56 loc) · 1.47 KB
/
jackpot.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
#include <unordered_map>
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
int main() {
ll cases;
cin >> cases;
while(cases--) {
ll items;
cin >> items;
map<ll, ll> bestfactors;
for(ll i = 0; i < items; i++) {
ll item;
cin >> item;
map<ll, ll> factorshere;
while(item > 1) {
bool broken = false;
for(ll j = 2; j <= sqrt(item) + 1; j++) {
if(item % j == 0) {
item /= j;
factorshere[j]++;
broken = true;
break;
}
}
if(!broken) {
factorshere[item]++;
item = 1;
}
}
for(auto i : factorshere) {
ll idx = i.first;
if(factorshere[idx] > bestfactors[idx]) {
bestfactors[idx] = factorshere[idx];
}
}
}
ll total = 1;
bool toobig = false;
for(auto i : bestfactors) {
total *= pow(i.first, i.second);
if(total > 1000000000) {
toobig = true;
break;
}
}
if(toobig) {
cout << "More than a billion." << endl;
}
else {
cout << total << endl;
}
}
}