您的位置:首页 > 其它

UVa 11461 - Square Numbers【数学,暴力】

2017-07-04 10:27 316 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456

题意

输入两个整数a和b,输出从a到b(包含a和b)的平方数的个数。直到输入0 0时程序结束

分析:

如果一个数n是平方数,(double)sqrt(n)-(int)sqrt(n)<1e-6。

下面给出AC代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
int count=0;
if(n==0&&m==0)break;
for(i=(int)(sqrt(n-0.1))+1;i*i<=m;i++)
{
count++;
}
printf("%d\n",count);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: