HDU/HDOJ 1099 Lottery
来源:互联网 发布:网络节点 加速器 编辑:程序博客网 时间:2024/05/01 17:23
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1042 Accepted Submission(s): 519
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
2517
Sample Output
3 511 -- 12 34046358 ------ 720720
Author
eddy
计算方法:
n*(1/1+1/2+1/3+...+1/n)
不过输出非常恶心
要各种注意
还好1Y ^_^
我的代码:
//n*(1/1+1/2+1/3+...+1/n)#include<stdio.h>#include<string.h>typedef __int64 ll;ll gcd(ll a,ll b){if(b==0)return a;elsereturn gcd(b,a%b);}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll numlen(ll n){ll l=0;while(n){n=n/10;l++;}return l;}int main(){ll n,son,mother,g,d,i;while(scanf("%I64d",&n)!=EOF){mother=1,son=0;for(i=1;i<=n;i++)mother=lcm(mother,i);for(i=1;i<=n;i++)son=son+mother/i;son=son*n;g=gcd(mother,son);son=son/g;mother=mother/g;d=son/mother;son=son%mother;if(son==0){printf("%d\n",d);continue;}ll l1=numlen(d);ll l2=numlen(mother);for(i=0;i<=l1;i++)printf(" ");printf("%I64d\n",son);printf("%I64d ",d);for(i=1;i<=l2;i++)printf("-");printf("\n");for(i=0;i<=l1;i++)printf(" ");printf("%I64d\n",mother);}return 0;}
- HDU/HDOJ 1099 Lottery
- HDOJ HDU 1099 Lottery
- Lottery Hdoj 1099
- HDOJ 1099 Lottery
- hdu 1099 lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- 【数学】 HDU 1099 Lottery
- HDU ACM 1099 Lottery
- HDU 1099 Lottery 乐透彩
- hdoj 1099 Lottery(期望)
- hdu 1099 Lottery 解题分析
- HDU—— 1099 Lottery
- HDU 1099 Lottery (数学问题模拟)
- HDU 2985 Another lottery(水题)
- Lottery
- Flex XML 的遍历
- 树型视的三个结构TVINSERTSTRUCT、TVITEM、NMTREEVIEW(转)
- 用java获得你电脑中的cpu数量
- 动态web开发框架:Java,javascript相关技术和框架汇总
- POJ2516 Minimum Cost 最大流最小费用典型题目
- HDU/HDOJ 1099 Lottery
- 内存占用率
- “简单事务操作”数据库(NO-SQL数据库)应用系统的可扩展性设计的十条原则
- c# tcp如何实现两个不同子网之间进行通讯?要有源代码!!
- POJ 3468 A Simple Problem with Integers
- 加密模式
- C语言中将绝对地址转换为函数指针以及跳转到内存指定位置处执行的技巧
- 杂记2
- 十大高明的Google搜索技巧