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

题意:不算难的题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef __int64 ll;
using namespace std;

int main() {
    int t, a, b, cas =1 ;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &a, &b);
        ll sum = 0;
        for (int i = a; i <= b; i++)
            sum += (ll)i * i * i;
        printf("Case #%d: ", cas++);
        printf("%I64d\n", sum);
    }
    return 0;
}
时间: 2024-11-05 06:09:33

HDU - 5053 the Sum of Cube的相关文章

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(上海网络赛)

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 题目大意: 求出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个数立方和. 所以可以选择打表(不知道立方和的公式,可以选择打表). 立方

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---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 b

杭电 5053 the Sum of Cube(求区间内的立方和)打表法

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

hdu 4825 Xor Sum(trie+贪心)

hdu 4825 Xor Sum(trie+贪心) 刚刚补了前天的CF的D题再做这题感觉轻松了许多.简直一个模子啊...跑树上异或x最大值.贪心地让某位的值与x对应位的值不同即可. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #define CLR(a,b) memset((a)

HDU 1024 Max Sum Plus Plus --- dp+滚动数组

HDU 1024 题目大意:给定m和n以及n个数,求n个数的m个连续子系列的最大值,要求子序列不想交. 解题思路:<1>动态规划,定义状态dp[i][j]表示序列前j个数的i段子序列的值,其中第i个子序列包括a[j], 则max(dp[m][k]),m<=k<=n 即为所求的结果 <2>初始状态: dp[i][0] = 0, dp[0][j] = 0; <3>状态转移: 决策:a[j]自己成为一个子段,还是接在前面一个子段的后面 方程: a[j]直接接在前面

[2016-03-28][HDU][1024][Max Sum Plus Plus]

时间:2016-03-28 17:45:33 星期一 题目编号:[2016-03-28][HDU][1024][Max Sum Plus Plus] 题目大意:从n个数字提取出一定数字组成m个部分,使得这个部分的总和最大 分析: dp[i][j]表示前i段计算第j个数字,dp[i][j] = max(dp[i - 1][j - 1] + a[j],dp[i][k] + a[j]); #include <algorithm> #include <cstring> #include &