杭电oj上第1099题,下面是我的代码从1到22都能运行出正确结果,为什么总是WA呢

#include<stdio.h>intmain(){__int64n,sum,sum1,i,a,b,l,c,d,m,k,k1,k2;while(scanf("%I64d... #include<stdio.h>
int main()
{
__int64 n,sum,sum1,i,a,b,l,c,d,m,k,k1,k2;
while(scanf("%I64d",&n)!=EOF)
{
sum=1;
sum1=0;
for(i=1;i<=n;i++)
{
if(i>=17)
sum=sum/128;
sum=sum*i;
}
for(i=1;i<=n;i++)
sum1=sum1+sum/i;
a=(n*sum1)/sum;
b=(n*sum1)%sum;
if(b==0)
printf("%I64d\n\n",a);
else
{
k1=sum;
k2=b;
for(;;)
{
k=k1%k2;
if(k==0)
break;
k1=k2;
k2=k;
}
sum=sum/k2;
b=b/k2;
c=0;
d=a;
while(d!=0)
{
c++;
d=d/10;
}
m=sum;
l=0;
while(m!=0)
{
l++;
m=m/10;
}
for(i=0;i<=c;i++)
printf(" ");
printf("%I64d\n",b);
printf("%I64d ",a);
for(i=1;i<=l;i++)
printf("-");
printf("\n");
for(i=0;i<=c;i++)
printf(" ");
printf("%I64d\n",sum);

}

}
return 0;
}
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
展开
 我来答
porker2008
2012-04-07 · TA获得超过1.4万个赞
知道大有可为答主
回答量:7066
采纳率:62%
帮助的人:1.1亿
展开全部
超过17的都错了。
主要问题在
if(i>=17)
sum=sum/128;

这是我写的代码

#include <stdio.h>

int g(int a, int b)
{
if(b==0) return a;
return g(b,a%b);
}

int main()
{
int zhengshu, fenzi, fenmu, n, i, gg, newfenmu,newfenzi;
while(scanf("%d",&n)==1)
{
zhengshu = fenzi = 0; // 整数部分和分子都是0
fenmu = 1; // 分母是1
for(i=1;i<=n;i++) // 加上 n/i
{
newfenmu = fenmu * i; // 新的分母
newfenzi = fenzi * i + fenmu * n; // 新的分子
gg = g(newfenmu, newfenzi); // 分子分母的最大公因数
fenmu = newfenmu / gg; // 约分后的分母
fenzi = newfenzi / gg; // 约分后的分子
zhengshu += fenzi / fenmu; // 提出整数部分
fenzi = fenzi % fenmu; // 化分真分数
}
if(fenzi==0) // 最后结果为整数
{
printf("%d\n",zhengshu);
}
else // 结果为非整数
{
gg = zhengshu;
while(gg)
{
putchar(' ');
gg/=10;
}
printf(" %d\n%d ",fenzi,zhengshu);
gg = fenmu;
while(gg)
{
putchar('-');
gg/=10;
}
putchar(10);
gg = zhengshu;
while(gg)
{
putchar(' ');
gg/=10;
}
printf(" %d\n",fenmu);
}
}
}

附带1-22的答案
1

3

1
5 -
2

1
8 -
3

5
11 --
12

7
14 --
10

3
18 --
20

26
21 --
35

129
25 ---
280

73
29 ---
252

551
33 ----
2520

551
37 ----
2310

9473
41 -----
27720

13433
45 -----
25740

18581
49 -----
24024

4129
54 -----
45045

340463
58 ------
720720

620743
62 ------
680680

1662439
67 -------
4084080

3704479
71 -------
3879876

408335
76 ------
739024

46533
81 ------
235144
kang3951923
2012-04-07
知道答主
回答量:19
采纳率:0%
帮助的人:8.2万
展开全部
能不能把题目贴上来,我这进不去那个网站。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式