您的位置:首页 > 其它

UVa 11461 - Square Numbers (水题)

2014-08-28 09:16 302 查看
A
Square Numbers
Input: Standard Input
Output: Standard Output


A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers a and b you will have to find out how many square numbers are there between a and b (inclusive).

Input
The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0<a≤b≤100000). Input is terminated by a line containing two zeroes. This line should not be processed.

Output

For each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between a and b (inclusive).

Sample Input Output for Sample Input

1 4

1 10

0 0

2

3

Problem Setter: Shahriar Manzoor

题意:

如果一个数可以携程一个整数的平方,则说它是一个完全平方数。输入正整数a,b,有多少个完全平方数介于ab之间。

之间就是(int)sqrt(b) - (int)sqrt(a-1)一定要先两个都转换为int才能相减

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#define oform1 "%lld"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define P64I1(a) printf(oform1, (a))
#define REP(i, n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));

int main() {
int s, t;

while(scanf("%d%d", &s, &t) != EOF && (s||t)) {
int ans = (int) sqrt(t) - (int) sqrt(s-1);
printf("%d\n", ans);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: