首页 技术 正文
技术 2022年11月23日
0 收藏 331 点赞 4,785 浏览 1659 个字

Lottery

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2061    Accepted Submission(s): 941

Problem DescriptionEddy’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? InputInput consists of a sequence of lines each containing a single positive integer n, 1<=n<=22, giving the size of the set of coupons. OutputFor 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 Input2
5
17 Sample Output3
5
11 —
12
340463
58 ——
720720 Authoreddy RecommendJGShining 

sum=n*∑(1/i);—–>n*(1+1/2+1/3+…..+1/n);

题意不好懂…..表示看来白天没明白….之后看了别人的讲的题意才懂的…..

之后的就不难了!

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int gcd(_int64 a,_int64 b)
{
if(b==)
return a;
gcd(b,a%b);
}; void swap(_int64 *a,_int64 *b)
{
*a^=*b,
*b^=*a,
*a^=*b;
}
int main()
{
int n,i;
char str[]={'\0'},num[]={'\0'};
_int64 a,b,c,real;
while(scanf("%d",&n)!=EOF)
{
a=b=;
for(i=;i<=n;i++)
{
a=a*i+b;
b*=i;
if(a<b) swap(a,b);
c=gcd(a,b);
a/=c;
b/=c;
}
if((n*a)%b)
{
real=(a/b)*n;
a%=b;
a*=n;
real+=a/b;
a%=b;
c=gcd(a,b);
a/=c;
b/=c;
itoa(b,str,);
itoa(real,num,);
for(i=;i<=strlen(num);i++)
printf(" ");
printf("%I64d\n%I64d ",a,real);
for(i=;i<strlen(str);i++)
printf("-");
puts("");
for(i=;i<=strlen(num);i++)
printf(" ");
printf("%I64d\n",b);
}
else
printf("%I64d\n",n*a/b);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844