暑期集训之立方求和
2017-07-21 20:47
246 查看
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
Sample Output
这道题虽然看上去非常简单,就是一个先立方再求和的原理,但实际上这道题的难点就是数据类型的考虑上,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;
}
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: 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;
}
相关文章推荐
- 暑期集训之ZOJ
- 暑期集训-dp46(3)数塔问题
- 杭电暑期多校集训—Time To Get Up
- 8.2 暑期集训—— 二分法
- 2016暑期集训1A 组合数
- 2016暑期集训1C 最长回文
- 暑期ACM集训-网络流
- hdu1873 看病要排序 (2016xynu暑期集训检测 -----E题)
- 7.13ACM暑期集训开始
- NBUT-2014暑期集训专题练习1 -> 二分法B - B
- 2132: 中南大学2017年ACM暑期集训前期训练题集(入门题)
- HDOJ2009暑期集训公开赛(1)-BAPC2008
- 2009ACM多校联合暑期集训(10)——NIT专场
- 8月1号!暑期集训!FIIIIIIIIIIGHT!
- LightOJ 1294 Positive Negative Sign 求和的升级版 暑期练习T
- 杭电暑期多校集训—KazaQ's Socks
- 暑期集训之喷水装置(二)
- SHU 2013 暑期集训(7-15)解题报告
- 杭电暑期多校集训—Questionnaire
- 2013.7.19 2013NBUT暑期集训成果赛