A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range[A,B].
2 1 3 2 5
Case #1: 36Case #2: 224
这道题虽然看上去非常简单,就是一个先立方再求和的原理,但实际上这道题的难点就是数据类型的考虑上,int型数据明显不够,所以在这里运用了double型数据,AC,代码如下:
#include<stdio.h> #include<math.h> main() { int t,f; scanf("%d",&t); f=t; while(t--) { int m,n; double i,b,sum=0; scanf("%d%d",&m,&n); for(i=m;i<=n;i++) { b=i*i*i; sum=sum+b; } printf("Case #%d: %.0lf\n",f-t,sum); } return 0; }