-
Notifications
You must be signed in to change notification settings - Fork 1
/
1024 - Eid.cpp
78 lines (77 loc) · 1.86 KB
/
1024 - Eid.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
#include<bits/stdc++.h>
using namespace std;
#define mx 102
int arr[mx] = {0};
vector<int> p;
void sieve()
{
p.push_back(2);
for(int i=4; i<mx; i+=2) arr[i] = 1;
for(int i=3; i<mx; i+=2){
if(arr[i] == 0){
p.push_back(i);
for(int j=i*i; j<mx; j+= i+i)
arr[j] = 1;
}
}
p.push_back(101);
}
string multiply( string a, int b ) {
// a contains the biginteger in reversed form
int carry = 0;
for( int i = 0; i < a.size(); i++ ) {
carry += (a[i] - 48) * b;
a[i] = ( carry % 10 + 48 );
carry /= 10;
}
while( carry ) {
a += ( carry % 10 + 48 );
carry /= 10;
}
return a;
}
int power(int a, int p)
{
if(p==0) return 1;
int x = power(a, p/2);
x = x*x;
if(p%2==1) x = x*a;
return x;
}
int main()
{
sieve();
int tc, n,a;
scanf("%d",&tc);
for(int cs=1; cs<=tc; cs++){
scanf("%d",&n);
map<int , int> mp;
for(int j=1; j<=n; j++){
scanf("%d",&a);
int i=0;
while(p[i]*p[i]<=a){
if(a%p[i]==0){
int pow = 0;
while(a%p[i]==0){
pow++;
a/=p[i];
}
mp[p[i]] = max(mp[p[i]], pow);
//cout<<p[i]<<" to "<<mp[p[i]]<<endl;
}
i++;
}
if(a>1)
mp[a] = max(mp[a], 1);
}
map<int, int>:: iterator it = mp.begin();
string ans = "1";
while(it != mp.end()){
ans = multiply(ans, power(it->first, it->second));
it++;
}
reverse(ans.begin(), ans.end());
printf("Case %d: %s\n", cs, ans.c_str());
}
return 0;
}