HDUOJ 1099——Lottery
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2061 Accepted Submission(s): 941
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
sum=n*∑(1/i);----->n*(1+1/2+1/3+.....+1/n);
题意不好懂.....表示看来白天没明白....之后看了别人的讲的题意才懂的.....
之后的就不难了!
代码:
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cstdlib>
5 using namespace std;
6 int gcd(_int64 a,_int64 b)
7 {
8 if(b==0)
9 return a;
10 gcd(b,a%b);
11 };
12
13 void swap(_int64 *a,_int64 *b)
14 {
15 *a^=*b,
16 *b^=*a,
17 *a^=*b;
18 }
19 int main()
20 {
21 int n,i;
22 char str[20]={' '},num[20]={' '};
23 _int64 a,b,c,real;
24 while(scanf("%d",&n)!=EOF)
25 {
26 a=b=1;
27 for(i=2;i<=n;i++)
28 {
29 a=a*i+b;
30 b*=i;
31 if(a<b) swap(a,b);
32 c=gcd(a,b);
33 a/=c;
34 b/=c;
35 }
36 if((n*a)%b)
37 {
38 real=(a/b)*n;
39 a%=b;
40 a*=n;
41 real+=a/b;
42 a%=b;
43 c=gcd(a,b);
44 a/=c;
45 b/=c;
46 itoa(b,str,10);
47 itoa(real,num,10);
48 for(i=0;i<=strlen(num);i++)
49 printf(" ");
50 printf("%I64dn%I64d ",a,real);
51 for(i=0;i<strlen(str);i++)
52 printf("-");
53 puts("");
54 for(i=0;i<=strlen(num);i++)
55 printf(" ");
56 printf("%I64dn",b);
57 }
58 else
59 printf("%I64dn",n*a/b);
60 }
61 return 0;
62 }
- Python3插入排序
- Python3冒泡排序
- Python Selenium设计模式-POM
- 【Python学习笔记之一】Python关键字及其总结
- 前后端分离了,然后呢?
- 【Python学习笔记之二】浅谈Python的yield用法
- LINUX中常用操作命令
- Java异常抛出及try,catch应用实例
- GitHub实战系列~2.把本地项目提交到github中 2015-12-10
- 前20名Python机器学习开源项目
- 接口测试 | 24 requests + unittest集成你的接口测试
- [快学Python3]数据结构与算法-二分查找
- 基于Excel参数化你的Selenium2测试
- 【LeetCode】关关刷题日记24-Leetcode 121. Best Time to Buy and Sell Stock
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Android | 《看完不忘系列》之Glide
- Android | 资源冲突覆盖的一些思考
- 如何获取流式应用程序中checkpoint的最新offset
- Spark之离线统计热点城市信息
- 使用OpenCV实现图像增强
- typescript基础篇(4):函数
- 这样的奇技淫巧,劝你不用也罢
- 一文详解设备ID的那些事儿
- Ansible搭建hadoop-3.1.3高可用
- Android | xml和view的那些事
- Android | Glide细枝篇
- 从源代码编译安装 MonoDevelop 记录
- 在 Asp.Net Core WebAPI 中防御跨站请求伪造攻击
- Hash 算法有哪些?
- Cordova 运行 Web 应用