-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUVA_12068.cpp
38 lines (35 loc) · 1003 Bytes
/
UVA_12068.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
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if ( b == 0 ) return a ;
else return GCD(b,a%b);
}
int main() {
long long t ;
scanf("%lld",&t);
for ( long long z = 1 ; z <= t ; z++ ) {
long long n,a ;
scanf("%lld",&n);
vector <long long > vec ;
for ( long long i = 0 ; i < n ; i++) {
scanf("%lld",&a);
vec.push_back(a);
}
long long last = vec[0];
long long index = 0 ;
long long result ;
while( index != vec.size()) {
result = (vec[index]*last)/GCD(vec[index],last);
last = result ;
index++ ;
}
long long sum = 0 ;
for (long long i = 0 ; i < vec.size() ; i++) {
sum = sum + (result/vec[i]);
}
result = n*result;
long long divisor = GCD(result,sum);
printf("Case %lld: %lld/%lld\n",z,result/divisor,sum/divisor);
}
return 0 ;
}