題目: 完全平方和
import java.util.Scanner;
import java.lang.Math;
public class Square{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
for(int i = 1; i <= n; i++){
int a = sc.nextInt();
int b = (int)Math.sqrt(sc.nextInt());
int calc = 0;
int s = (int)Math.sqrt(a);
a = (a > 1) ? ((s*s < a) ? s + 1 : s) : 1;
for(; a <= b; a++){
calc += (a*a);
}
System.out.println("Case " + i + ": " + calc);
}
}
}
}
沒有留言:
張貼留言