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

题目链接: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代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,m,i;
 6     while(scanf("%d%d",&n,&m)!=EOF)
 7     {
 8         int count=0;
 9         if(n==0&&m==0)break;
10         for(i=(int)(sqrt(n-0.1))+1;i*i<=m;i++)
11         {
12                 count++;
13         }
14         printf("%d\n",count);
15     }
16     return 0;
17 }

 

posted @ 2017-07-04 10:27  Angel_Kitty  阅读(500)  评论(0编辑  收藏  举报