HDU-5053 the Sum of Cube

来源:互联网 发布:淘宝宝贝描述上传图片 编辑:程序博客网 时间:2024/05/16 08:33
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


Problem Description
A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
 

Input
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].
 

Output
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.
 

Sample Input
21 32 5
 

Sample Output
Case #1: 36Case #2: 224
 

Source
2014 ACM/ICPC Asia Regional Shanghai Online
 

Recommend
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;
}


0 0