This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
ArrayList<Integer> list=new ArrayList<Integer>(); | |
int i=1,num=1; | |
while(num<=100000){ | |
list.add(num); | |
i++; | |
num=i*i; | |
} | |
while(true){ | |
int a=scn.nextInt(),b=scn.nextInt(),count=0; | |
if(a==0&&b==0) | |
break; | |
if(a==b) | |
b++; | |
for(int k=0;k<list.size();k++){ | |
if(list.get(k)>=a&&list.get(k)<=b) | |
count++; | |
} | |
System.out.println(count); | |
} | |
} | |
/*題目:Q11461:Square Numbers | |
作者:1010 | |
時間:西元 2017 年 3 月 */ | |
} |
這題用ArrayList先建表,計算輸入a、b序列中有幾個是符合平方的數
沒有留言:
張貼留言