Sum of squares and cubes and
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 91523 accepted submission (s): 29316
Problem description gives a continuous integer and calculates the sum of squares of all even numbers and the sum of all odd numbers.
The input data contains multiple groups of test instances. Each group of test instances contains a row consisting of two integers, M and N.
Output for each group of input data, the output line should contain two integers x and y, indicating the sum of the squares of all the even numbers in the continuous integer of the segment and the sum of all the odd numbers of cubes and.
You can think that a 32-bit integer is enough to save the result.
Sample input1 32 5
Sample output4 28
1 #include<cstdio> 2 int main() 3 { 4 int m,n; 5 while(scanf("%d%d",&m,&n)==2) 6 { 7 int j=0,o=0,t; 8 if(m>n){t=m;m=n;n=t;} 9 for(int i=m;i<=n;i++)10 if(i%2)j=j+i*i*i; 11 else o=o+i*i; 12 printf("%d %d\n",o,j);13 }14 return 0;15 }
20 152
Hangzhou (Hangzhou), 2007 08:35:26