首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

杭电 1018 ,测试数据正确,为什么老是compilation error,求大牛给看看,该如何解决

2012-04-23 
杭电 1018 ,测试数据正确,为什么老是compilation error,求大牛给看看In many applications very large int

杭电 1018 ,测试数据正确,为什么老是compilation error,求大牛给看看
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.

Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.

Output
The output contains the number of digits in the factorial of the integers appearing in the input

Sample Input
2
10
20
 
Sample Output
7
19
 
代码(用的vc):

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,num,group;
double s;
cin>>group;
while(group)
{
s=0;
cin>>num;
for(i=1;i<=num;i++)
{
s+=log10(i);
}
s=(int)s+1;
cout<<s<<endl;
group--;
}
system("pause");
return 0;
}

[解决办法]
s=(int)s+1;

这里s是什么类型。。
[解决办法]
如下修改AC:

s+=log10((double)i); //s+=log10(i);
 }
 //s=(int)s+1;
 cout<<(int)s+1<<endl; //cout<<s<<endl;


[解决办法]
s+=log10((double)i); 这样就不会语法错误了

热点排行