uva 11461 - Square Numbers(数论)

题意:给出a,b,求a~b间平方数的个数。

 

思路:sqrt(b) - sqrt(a-1),注意一下精度误差。

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <math.h>
 4  
 5 int main () {
 6     int a, b;
 7     while (scanf("%d%d", &a, &b) == 2 && a + b) {
 8         int l=sqrt(a-1),r=sqrt(b);
 9         printf("%d\n",r-l);
10     }
11     return 0;
12 }
View Code

猜你喜欢

转载自www.cnblogs.com/ljy08163268/p/11705956.html