LA 3288

3288 - Harmonic Mean

 * http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=3288

Summary
Given of a sequence of several integers, compute their harmonic mean.

Explanation
This is the easiest problem of this contest. It was just required to write a program, doing the calculation described in the problem statement.

It should be noted, that the output values may not fit in standard 32-bit integer type.

Sample Solution

 * 1) include 

typedef unsigned long long num; num gcd(num x, num y) { return y==0 ? x : gcd(y,x%y); }

int main {   int i, c, t, n;    for (scanf("%d", &t), c = 1; c <= t && scanf("%d", &n) == 1; c++) { num a=0, b=1, x;       for (i = 0; i < n && scanf("%llu", &x) == 1; i++) a=a*x+b, b*=x; b *= n; x=gcd(a,b); printf("Case %d: %llu/%llu\n", c, b/x, a/x); }   return 0; }

Input
5 4 1 2 3 4 4 2 2 3 1 9 100 100 100 100 100 100 100 100 100 9 100 99 98 97 96 95 94 93 92 91 90 9 1 1 1 1 1 1 1 1 1

Output
Case 1: 48/25 Case 2: 12/7 Case 3: 100/1 Case 4: 2157130870725600/22486388502029 Case 5: 8190/821