/**
* 平方和与立方和
* 所有偶数的平方和以及所有奇数的立方和
*/
import java.util.*;
public class acm2007 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int firstNum, lastNum;
int sum1 = 0;
int sum2 = 0;
firstNum = in.nextInt();
lastNum = in.nextInt();
// 判断输入第一个数是否大于第二个数
if (firstNum > lastNum) {
int temp = lastNum;
lastNum = firstNum;
firstNum = temp;
}
for (int i = firstNum; i <= lastNum; i++) {
if (i % 2 != 0) {
sum2 = sum2 + i * i * i; // 奇数立方和
} else {
sum1 = sum1 + i * i; // 偶数平方和
}
}
System.out.print(sum1);
System.out.print(" ");
System.out.println(sum2);
}
}
}
时间: 2024-10-12 15:49:20