I - the Sum of Cube

水深无声 2022-06-01 07:58 254阅读 0赞

#

HPU专题训练(-1)GCD&&素筛&&快速幂_____I - 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

  1. 2
  2. 1 3
  3. 2 5

Sample Output

  1. Case #1: 36
  2. Case #2: 224
  3. /*
  4. 计算范围内的立方和
  5. */
  6. #include<stdio.h>
  7. int main()
  8. {
  9. int t;
  10. scanf("%d",&t);
  11. for(int j=1;j<=t;j++)
  12. {
  13. long long int a,b,sum=0;
  14. scanf("%lld %lld",&a,&b);
  15. for(long long int i=a;i<=b;i++)
  16. {
  17. sum+=i*i*i;
  18. }
  19. printf("Case #%d: %lld\n",j,sum);
  20. }
  21. return 0;
  22. }

发表评论

表情:
评论列表 (有 0 条评论,254人围观)

还没有评论,来说两句吧...

相关阅读