zoukankan      html  css  js  c++  java
  • Lottery hdu1099

    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;
    }
  • 相关阅读:
    大型应用程序中的资源destory办法
    PNG格式说明
    北山白云里,隐者自怡悦。
    常量和变量:public static const 和public static var
    60个最佳新年2012年日历壁纸
    想象渲染:3优秀的D室内设计模型的设计案例
    强大的JavaScript表单验证插件
    带给你灵感的3D街画艺术设计
    铁道部购票网站存泄密危险 CDN服务商技术短板是主因
    GNU make manual 翻译( 一百二十五)
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2229004.html
Copyright © 2011-2022 走看看