the Sum of Cube

A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
InputThe first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve. 
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range[A,B]. OutputFor each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then output the answer – sum the cube of all the integers in the range. Sample Input
2
1 3
2 5
Sample Output
Case #1: 36
Case #2: 224
#include<stdio.h>
int main(){
	int T,Cas=1;
	long long a,b; 
	scanf("%d",&T);
	while(T--){
		long long c=0;
		scanf("%lld%lld",&a,&b);
		for(long long i=a;i<=b;i++){
			c+=i*i*i;
		} 
		printf("Case #%d: %lld\n",Cas++,c);
	}
	return 0;
} //注意数字的范围不要爆掉就行了

猜你喜欢

转载自blog.csdn.net/miku531/article/details/79252463
sum