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;
    }
  • 相关阅读:
    requireJS的优化工具 ---- r.js
    requireJS基本配置相关
    利用thread和sleep生成字符串的伪随机序列
    操作系统虚拟内存中的四种典型页替换算法(OPT,LRU,FIFO,Clock)
    考虑一个特殊的hash函数h,能将任一字符串hash成一个整数k……
    二叉树的遍历(C++非递归实现)
    判断一点是否在一条射线的左边
    如何判断单链表是否存在环
    移位数组的二分查找
    字符串相关函数的实现
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2229004.html
Copyright © 2011-2022 走看看