//Coupons
/*
Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a prize (a cereal box, of course).
With one coupon per box, how many boxes on average are required to make a complete set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1<=n<=33,
giving the size of the set of coupons. Input is terminated by end of file.
Output
For each input line, output the average number of boxes required to collect the complete set of n coupons.
If the answer is an integer number, output the number.
If the answer is not integer, then output the integer part of the answer followed by a space
and then by the proper fraction in the format shown below.
The fractional part should be irreducible.
There should be no trailing spaces in any line of output.
Sample Input
2
5
17
Sample Output
3
5
11 --
12
340463
58 ------
720720
*/
//算法分析,假设当前已经有k种Coupons,那么获得新的Coupons的概率为(n-k)/n,所需要的步数的期望值是(n)/(n-k)
//那么得到n种Coupons的期望就是其和,即n/n+n/(n-1)+n/(n-2)+.....+n/1
#include<iostream>
using namespace std;
typedef long long LL;
LL Gcd(LL A,LL B){
LL Tmp;
/*
while (B>0){
Tmp = A%B;
A = B;
B = Tmp;
}
return A;
*/
//Or Just below:
return A%B>0?Gcd(B,A%B):B;
}
class Fraction{
public:
Fraction(){
num = 0;
deno = 1;
}
Fraction(LL n, LL d=1){
if (d < 0){
n = -n;
d = -d;
}
num = n;
deno = d;
LL tmp = Gcd(num, deno);
num =num / tmp;
deno = deno / tmp;
}
Fraction operator +(const Fraction &plus)const{
return Fraction(num*plus.deno+deno*plus.num,deno*plus.deno);
}
Fraction operator -(const Fraction &minus)const{
return Fraction(num*minus.deno - deno*minus.num, deno*minus.deno);
}
int deno;//分母
int num;// 分子
};
int main(){
int n;
while (cin >> n){
Fraction Sum(0,1);
int i = 0;
while (i<n){
Sum = Sum + Fraction(n,n-i);
i++;
}
//cout << Sum.num << " " << Sum.deno << endl;
LL left = Sum.num/Sum.deno;
LL top = Sum.num%Sum.deno;
if (top != 0){
for (int j = left; j>0; j /= 10) cout << " ";
cout << " "<<top << endl;
cout << left;
for (int j = Sum.deno; j > 0; j /= 10)cout << "-";
cout << endl;
for (int j = left; j >0; j /= 10) cout << " ";
cout << " " << Sum.deno << endl;
}
else
cout << left << endl;
}
return 0;
}
/*
Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a prize (a cereal box, of course).
With one coupon per box, how many boxes on average are required to make a complete set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1<=n<=33,
giving the size of the set of coupons. Input is terminated by end of file.
Output
For each input line, output the average number of boxes required to collect the complete set of n coupons.
If the answer is an integer number, output the number.
If the answer is not integer, then output the integer part of the answer followed by a space
and then by the proper fraction in the format shown below.
The fractional part should be irreducible.
There should be no trailing spaces in any line of output.
Sample Input
2
5
17
Sample Output
3
5
11 --
12
340463
58 ------
720720
*/
//算法分析,假设当前已经有k种Coupons,那么获得新的Coupons的概率为(n-k)/n,所需要的步数的期望值是(n)/(n-k)
//那么得到n种Coupons的期望就是其和,即n/n+n/(n-1)+n/(n-2)+.....+n/1
#include<iostream>
using namespace std;
typedef long long LL;
LL Gcd(LL A,LL B){
LL Tmp;
/*
while (B>0){
Tmp = A%B;
A = B;
B = Tmp;
}
return A;
*/
//Or Just below:
return A%B>0?Gcd(B,A%B):B;
}
class Fraction{
public:
Fraction(){
num = 0;
deno = 1;
}
Fraction(LL n, LL d=1){
if (d < 0){
n = -n;
d = -d;
}
num = n;
deno = d;
LL tmp = Gcd(num, deno);
num =num / tmp;
deno = deno / tmp;
}
Fraction operator +(const Fraction &plus)const{
return Fraction(num*plus.deno+deno*plus.num,deno*plus.deno);
}
Fraction operator -(const Fraction &minus)const{
return Fraction(num*minus.deno - deno*minus.num, deno*minus.deno);
}
int deno;//分母
int num;// 分子
};
int main(){
int n;
while (cin >> n){
Fraction Sum(0,1);
int i = 0;
while (i<n){
Sum = Sum + Fraction(n,n-i);
i++;
}
//cout << Sum.num << " " << Sum.deno << endl;
LL left = Sum.num/Sum.deno;
LL top = Sum.num%Sum.deno;
if (top != 0){
for (int j = left; j>0; j /= 10) cout << " ";
cout << " "<<top << endl;
cout << left;
for (int j = Sum.deno; j > 0; j /= 10)cout << "-";
cout << endl;
for (int j = left; j >0; j /= 10) cout << " ";
cout << " " << Sum.deno << endl;
}
else
cout << left << endl;
}
return 0;
}