UV-11461 square numbers

Source: Internet
Author: User

A squarenumber is an integer number whose square root is also an integer. for example1, 4, 81 are some square numbers. given two numbers A and B you will have tofind out how many square numbers are there between A and B (random SIVE ).

 

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 shoshould not beprocessed.

 

Output

For each lineof input produce one line of output. This line contains an integer whichdenotes how many square numbers are there between A and B (random SIVE ).

 

Sampleinput outputfor sample input
1 4
1 10
0 0

2

3

 

Problem setter: Shahriar Manzoor

Question: calculate the total number of partitions between [a, B ].

Idea: amount .... The root number is the answer.

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;int main() {int a, b;while (scanf("%d%d", &a, &b) != EOF && a+b) {int n = sqrt(a);int m = sqrt(b);int ans = m-n+1;if (n*n < a)ans--;printf("%d\n", ans);}return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.