the sum of cube 立方和
2017-01-30 19:41
309 查看
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 rangeA,BA,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 �C sum the cube of all the integers in the range.Sample Input
2 1 3 2 5Sample Output
Case #1: 36 Case #2: 224
两种解法
公式不会推百度的
#include<cstdio>int main(){int t;scanf("%d",&t);for (int k=1;k<=t;++k){long long s,d;scanf("%lld%lld",&s,&d);/*long long sum=0;for (long long i=s;i<=d;++i){sum+=i*i*i;}printf("Case #%d: %lld\n",k,sum);*/printf("%lld\n",(d*(d+1)/2)*(d*(d+1)/2)-(s*(s-1)/2)*(s*(s-1)/2));}return 0;}
相关文章推荐
- 解决ORA-04030报错
- 不要62
- C#字符串的操作
- ASP.NET MVC 5 中使用Frameset中Session、Cookie值消失的问题完整解决方案
- Asp.net mvc 知多少(四)
- 美素数
- 中心极限定理
- P1083 借教室
- [Treap套权值线段树 线段树分裂与合并] BZOJ 4552 [Tjoi2016&Heoi2016]排序
- P1553 数字反转(升级版)(洛谷)
- uva 11045 My T-shirt suits me
- Android studio里搜索不到Genymotion,哪么如何正确的解决这问题尼!!!
- 素数判定
- 素数判定
- 重新复习C语言 大多数还是语法、算法的问题
- c3p0 配置文件 各个属性的意义
- 44、判断是否符合指定格式
- 字符串面试题(四)— 判断一个字符串是否为另外一个字符串旋转之后的字符串
- [后缀自动机 线段树] BZOJ 1396 识别子串 & BZOJ 2865 字符串识别
- 金圣叹批评版水浒传上 - 笔记