hdu 5053 the Sum of Cube---2014acm上海赛区网络赛

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053

the Sum of Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 140    Accepted Submission(s): 80

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

2
1 3
2 5

Sample Output

Case #1: 36
Case #2: 224

Source

2014 ACM/ICPC Asia Regional Shanghai Online

Recommend

hujie   |   We have carefully selected several similar problems for you:  5052 5051 5049 5048 5046

Statistic | Submit | Discuss | Note

一道送分题,不过要小心中间过程溢出。。。

//#pragma comment(linker, "/STACK:36777216")
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
int main(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt","r",stdin);
    #endif
    int T,kase=0;
    scanf("%d",&T);
    while(T--){
        printf("Case #%d: ",++kase);
        long long A,B;
        scanf("%I64d%I64d",&A,&B);
        long long sum=0;
        long long sum1=(A-1)*(A)/2;
        sum1=sum1*sum1;
        long long sum2=(B)*(B+1)/2;
        sum2=sum2*sum2;
        cout<<sum2-sum1<<endl;
    }
    return 0;
}
时间: 2024-10-06 11:15:56

hdu 5053 the Sum of Cube---2014acm上海赛区网络赛的相关文章

hdu 5053 the Sum of Cube(上海网络赛)

the Sum of Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 405    Accepted Submission(s): 224 Problem Description A range is given, the begin and the end are both integers. You should sum

HDU 5053 the Sum of Cube(数学求立方和)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053 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), whic

HDU - 5053 the Sum of Cube

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 so

2014上海网络赛 HDU 5053 the Sum of Cube

水 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include<math.h> 4 #include<iostream> 5 #define LL long long 6 using namespace std; 7 8 int main() 9 { 10 int t; 11 int a,b; 12 int cas; 13 LL sum; 14 while(~scanf("%d",&

HDU 5053 the Sum of Cube(简单数论)

http://acm.hdu.edu.cn/showproblem.php?pid=5053 题目大意: 求出A^3+(A+1)^3+(A+2)^3+...+B^3和是多少 解题思路: 设f(n)=1~n的立方和,则A^3+(A+1)^3+(A+2)^3+...+B^3=f(B) - f(A - 1) 题目给的数的范围是1~10000,1~10000立方和不会超过__int64(long long)的范围.由于是10000个数立方和. 所以可以选择打表(不知道立方和的公式,可以选择打表). 立方

hdu 5050 Divided Land---2014acm上海赛区网络赛

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5050 Divided Land Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 115    Accepted Submission(s): 57 Problem Description It's time to fight the loc

hdu 4023 2011上海赛区网络赛C 贪心+模拟

以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 10000000

hdu 4027 2011上海赛区网络赛 线段树 成段平方根 ***

不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #de

hdu 4026 2011上海赛区网络赛F TSP ****

没看过TSP,先mark 1 //4838039 2011-10-27 23:04:15 Accepted 4026 2343MS 31044K 3143 B C++ Geners 2 //状态压缩DP的TSP问题 3 //优先级位运算小于判等 , 还有各种细节各种出错 4 #include <cstdio> 5 #include <cstring> 6 #include <stdlib.h> 7 #define mabs(a) (a>0?a:-(a)) 8 9