码迷,mamicode.com
首页 > 其他好文 > 详细

完全平方数的个数

时间:2014-12-01 00:35:33      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   color   os   sp   java   on   

描述

给定整数区间[A,B]问其中有多少个完全平方数。

bubuko.com,布布扣

 

 
输入
多组数据,包含两个正整数A,B 1<=A<=B<=2000000000。
输出
每组数据输出一行包含一个整数,表示闭区间[A,B]中包含的完全平方数的个数。
样例输入
1 1
1 2
3 10
3 3
样例输出
1
1
2
0

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner scanner=new Scanner(System.in);
 6         int a;
 7         int b;
 8         int start;
 9         int end;
10         
11         while(scanner.hasNext()){
12             a=scanner.nextInt();
13             b=scanner.nextInt();
14             
15             start=(int)Math.ceil(Math.sqrt(a));
16             end=(int)Math.floor(Math.sqrt(b));
17             System.out.println(end-start+1);
18         }
19     }
20 }
21             
22             

 

 

完全平方数的个数

标签:style   blog   http   ar   color   os   sp   java   on   

原文地址:http://www.cnblogs.com/zqxLonely/p/4134000.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!