Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
4 28
20 152
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int m = sc.nextInt();
int oddSum = 0;
int evenSum = 0;
if(n>m){
n = n^m;
m = n^m;
n = n^m;
}
for(int i=n;i<=m;i++){
if(i%2==0){
evenSum += i*i;
}else{
oddSum += i*i*i;
}
}
System.out.println(evenSum+" "+oddSum);
}
}
}