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)的平方数的个数。

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

 

目录
相关文章
codeforces327——A. Flipping Game(前缀和)
codeforces327——A. Flipping Game(前缀和)
82 0
CodeForces 6A-Triangle(枚举/暴力)
CodeForces 6A-Triangle(枚举/暴力)
|
人工智能 BI
Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:stand...
1211 0
|
算法
UVa 10341 - Solve It【经典二分,单调性求解】
原题: Solve the equation:         p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0         where 0 0) 15 { 16 printf("No solut...
880 0
Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给...
1160 0
|
人工智能 C++
Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Friends are going to play console.
1249 0
|
Java
HDU 2147 kiki&#39;s game(规律,博弈)
kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others)Total Submission(s): 10763    Accepted Submission(s): ...
889 0