Uva 11461 - Square Numbers 解题报告(水题)

96 篇文章 0 订阅
该博客介绍了如何解决Uva在线判题平台上的11461题——平方数问题。题目要求在两个整数a和b之间(包括a和b),找出有多少个数的平方根也是整数。输入包含最多201行,每行有两个整数a和b(0<a≤b≤100000),以两个零结束。博客提供输出格式示例,输出应为整数,表示a和b之间平方数的数量。
摘要由CSDN通过智能技术生成

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

 



    解题报告: 预处理,二分查找。水题呀~
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int num[1000];
int top;

void init()
{
    int t=1;
    while(t*t<=100000)
        num[top++]=t*t,t++;
    num[top++]=100001;
}

int main()
{
    init();

    int l,r;
    while(~scanf("%d%d",&l,&r) && (l||r))
    {
        int posl = lower_bound(num,num+top,l)-num;
        int posr = lower_bound(num,num+top,r+1)-num;
        printf("%d\n", posr-posl);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值