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;
    }
  • 相关阅读:
    Clojure实现的简单短网址服务(Compojure、Ring、Korma库演示样例)
    android4.4系统解决“ERRORcouldn&#39;t find native method”方法
    JS window.open()属性
    网页视频播放器代码大全 + 21个为您的站点和博客提供的免费视频播放器
    理解Java的GC日志
    图像识别技术
    堆排序原理及算法实现(最大堆)
    什么是依赖注入
    Cocos2d-x3.1下实现相似iOS页面滑动指示圆点
    [Bootstrap] 6. Navigation
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2229004.html
Copyright © 2011-2022 走看看