HDU-5053 the Sum of Cube
2016-04-21 18:57
405 查看
http://acm.hdu.edu.cn/showproblem.php?pid=5053怎么说呢,一看这道题目我以为要用大数呢,但估计一下,10000*10000*10000=1000000000000 1000000000000*1000<long long的最大值,所以可以用long long。但即使是这样还是贡献了好几次wrong,下次一定要记得要用long long 的时候,所有与long long 有联系的数一定都要用long long型的。因为计算机运算long long( 占8字节),与int(4字节的)不同。
Total Submission(s): 1218 Accepted Submission(s): 484
[align=left]Problem Description[/align]A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
[align=left]Input[/align]The 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].
[align=left]Output[/align]For 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.
[align=left]Sample Input[/align]2
1 3
2 5
[align=left]Sample Output[/align]Case #1: 36
Case #2: 224
[align=left]Source[/align]2014 ACM/ICPC Asia Regional Shanghai Online
[align=left]Recommend[/align]hujie | We have carefully selected several similar problems for you: 5107 5106 5105 5104 5103 分#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 1000010
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
ll sum;
ll n,m;////n,m也用long long
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
while(~scanf("%d",&t))
{
for(int j=1;j<=t;j++)
{
scanf("%I64d%I64d",&n,&m);
sum=0;
for(ll i=n;i<=m;i++)
sum+=(ll)(i*i*i);
printf("Case #%d: %I64d\n",j,sum);
}
}
return 0;
}
the Sum of Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1218 Accepted Submission(s): 484
[align=left]Problem Description[/align]A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
[align=left]Input[/align]The 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].
[align=left]Output[/align]For 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.
[align=left]Sample Input[/align]2
1 3
2 5
[align=left]Sample Output[/align]Case #1: 36
Case #2: 224
[align=left]Source[/align]2014 ACM/ICPC Asia Regional Shanghai Online
[align=left]Recommend[/align]hujie | We have carefully selected several similar problems for you: 5107 5106 5105 5104 5103 分#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#define maxn 1000010
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
ll sum;
ll n,m;////n,m也用long long
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;
while(~scanf("%d",&t))
{
for(int j=1;j<=t;j++)
{
scanf("%I64d%I64d",&n,&m);
sum=0;
for(ll i=n;i<=m;i++)
sum+=(ll)(i*i*i);
printf("Case #%d: %I64d\n",j,sum);
}
}
return 0;
}
相关文章推荐
- POJ 2352 Stars
- 1A. Theatre Square
- HDU 2046骨牌铺方格(滚动数组)
- andorid 图片加载总结
- HDU 1166 敌兵布阵
- HDU 2097Sky数
- HOJ 1876经理的烦恼
- A Mathematical Curiosity
- LeetCode145 Binary Tree Postorder Traversal(迭代实现) Java
- SharePoint轻量化应用之HR系统构建-人才归档 及隐藏参数界面设计
- 个人博客总结3
- struts action和jsp之间的传值
- floyd算法&迪杰斯特拉算法
- 【转载】继承(C#)
- 微机的非移位指令
- POJ 2533 LIS N2
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU 1505City Game
- ibatis----IBM
- stl-algorithm用法