Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1108 Accepted Submission(s): 544
Problem Description
Eddy's company publishes a kind of lottery.This set of lottery which are numbered 1 to n, and a set of one of each is required for a prize .With one number per lottery, how many lottery 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<=22, giving the size of the set of coupons.
Output
For each input line, output the average number of lottery 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 ouput.
Sample Input
2 5 17
Sample Output
3 5 11 -- 12 340463 58 ------ 720720
Author
eddy
Recommend
JGShining
题目没有看懂啊~~~~
/*****************************************************************
HDU 1099
*****************************************************************/
#include<iostream>
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()
{
int i,n;
long long number,n1,n2;
long long integer;
long long fenzi,fenmu;
long long a[23];
a[1]=1;
for(i=2;i<=22;i++)a[i]=i*a[i-1]/gcd(i,a[i-1]);
while(scanf("%d",&n)!=EOF)
{
fenzi=0;
for(i=1;i<=n;i++) fenzi+=a[n]/i;
fenzi*=n;
number=gcd(fenzi,a[n]);
fenzi=fenzi/number;
fenmu=a[n]/number;
integer=fenzi/fenmu;
fenzi-=integer*fenmu;
if(fenzi==0)
{
printf("%I64d\n",integer);continue;
}
int size1=0,size2=0;
n1=integer;n2=fenmu;
while(n1!=0){size1++;n1/=10;}
while(n2!=0){size2++;n2/=10;}
for(i=0;i<=size1;i++)printf("");
printf("%I64d\n",fenzi);
printf("%I64d ",integer);
for(i=0;i<size2;i++)printf("-");
printf("\n");
for(i=0;i<=size1;i++)printf("");
printf("%I64d\n",fenmu);
}
return 0;
}