HDU 1099 Lottery

Lottery

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4348    Accepted Submission(s): 1934


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
 
 
 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,i,j,a,b,c;
 7     int fz[23]={0},fm[23]={0},zs[23]={0};
 8     int sum=1, gbs=1;
 9     zs[1]=1;
10     for(i=2; i<=22; i++)
11     {
12         for(j=1; j<=i; j++)
13         {
14             if(j*gbs%i==0)
15             {
16                 gbs=j*gbs;
17                 sum=j*sum+gbs/i;
18                 fm[i]=gbs/i;
19                 zs[i]=sum/fm[i];
20                 fz[i]=sum%fm[i];
21                 a=fm[i];
22                 b=fz[i];
23                 while(b!=0)
24                 {
25                     c=a%b;
26                     a=b;
27                     b=c;
28                 }
29                 fz[i]=fz[i]/a;
30                 fm[i]=fm[i]/a;
31                 break;
32             }
33         }
34     }
35     while(cin>>i)
36     {
37         if(fz[i])
38         {
39             int lin=zs[i], len=2, num=1;
40             while(lin/10)
41             {
42                 lin/=10;
43                 len++;
44             }
45             lin=fm[i];
46             while(lin/10)
47             {
48                 lin/=10;
49                 num++;
50             }
51             cout<<string(len, ' ')<<fz[i]<<endl;
52             cout<<zs[i]<<' '<<string(num, '-')<<endl;
53             cout<<string(len, ' ')<<fm[i]<<endl;
54         }
55         else
56         {
57             cout<<zs[i]<<endl;
58         }
59     }
60     return 0;
61 }

 

转载于:https://www.cnblogs.com/zhaopeng938/p/9418703.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值