您的位置:首页 > 其它

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字节的)不同。

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: