1.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* @author Beinhofer Christian
* @version 1.0
*
* Wahrscheinlichkeitstheorie
* 8952966 10288 Coupons Accepted C++ 0.012 2011-06-15 11:49:57
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=14&problem=1229
*/

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>

typedef unsigned long long uint64;

// GCD algo from wikipedia
uint64 gcd(uint64 u, uint64 v){
if(u == v || u == 0 || v == 0)
return u|v;
if(u%2 == 0){ // if u is even
if(v%2 == 0) // if u and v are even
return (2*gcd(u/2, v/2));
else // u is even and v is odd
return gcd(u/2, v);
}
else if(v%2 == 0) // if u is odd and v is even
return gcd(u, v/2);
else{ // both are odd
if(u>=v)
return gcd((u-v)/2, v);
else
return gcd((v-u)/2, u);
}
}

int main(int argc, char* argv[])
{
int n;

while(scanf("%d", &n) != EOF)
{
// calculate n * (1 + 1/2 + 1/3 +... 1/n)
uint64 num = 0;
uint64 den = 144403552893600; // n max is 33 -> LCM(1,2,...,33) = 144403552893600;
for(int k = 1; k <= n; k++)
num = num + den / k;

num = n*num;

// fractional part should be irreducible
uint64 GCD = gcd(num, den);
num /= GCD;
den /= GCD;

// Extract the integer part
int full = int(num / den);
num = num % den;

// output
if(num == 0)
{
printf("%d\n", full);
}
else
{
int fc = int(log10(double(full))) + 2;
int dc = int(log10(double(den))) + 1;

for(int i = 0; i < fc; i++)
printf(" ");
printf("%lli\n", num);

printf("%i ", full);
for(int i = 0; i < dc; i++)
printf("-");
printf("\n");

for(int i = 0; i < fc; i++)
printf(" ");
printf("%lli\n", den);
}
}

return 0;
}