csdn 第五届在线编程大赛月赛第一题:完全平方数的个数,提示我未在规定时间内输出结果
茂升快跑 2014-10-10 10:13:28 我今天晚上尝试了一下csdn 第五届在线编程大赛月赛第一题:完全平方数的个数,在本地输出结果是没有问题的,在线编译也没有,提交代码以后返回结果:挑战失败,未在规定时间内输出结果。 程序本身没有死循环,我用到了一个sqrt函数,我看到网上有人贴出了java代码也是采用了sqrt函数,这道题存在效率问题吗?
下面是我的代码:
#include <stdio.h>
#include <math.h>
int main(int argc, char const *argv[]){
int numA = 0;
int numB = 0;
double result = 0.0;
int count = 0;
int temp = 0;
while(scanf("%d %d", &numA, &numB) != EOF){
count = 0;
for (int i = numA; i <= numB; ++i){
result = sqrt(i);
temp = (int)result;
if (temp * temp == i){
count++;
}
}
printf("%d\n", count);
}
// int num = 2000000000;
return 0;
}