杭电 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. 
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

 1 #include<cstdio>
 2 __int64 a[1000000]={0,1};
 3 int main()
 4 {
 5     for(__int64 i=1;i<=1000000;i++)
 6     {
 7         a[i]=a[i-1]+i*i*i;
 8     }
 9     __int64 t,k=0;;
10     scanf("%I64d",&t);
11     while(t--)
12     {
13         __int64 m,n;
14         scanf("%I64d%I64d",&m,&n);
15         printf("Case #%I64d: %I64d\n",++k,a[n]-a[m-1]);
16     }
17 }
时间: 2025-01-06 19:17:25

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

杭电 1003 Max Sum

http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142781    Accepted Submission(s): 33242 Problem Description Given a sequence a[1],a[2],a[3

HDU4622:Reincarnation(后缀数组,求区间内不同子串的个数)

Problem Description Now you are back,and have a task to do: Given you a string s consist of lower-case English letters only,denote f(s) as the number of distinct sub-string of s. And you have some query,each time you should calculate f(s[l...r]), s[l

HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5101    Accepted Submission(s): 2339 Problem Description Mario is world-famous plumber. His “burly” figure and amazing jumping abilit

hdu3709(求区间内平衡数的个数)数位dp

题意:题中平衡数的定义: 以一个位置作为平衡轴,然后左右其他数字本身大小作为重量,到平衡轴的距离作为全职,实现左右平衡(即杠杆原理平衡).然后为区间[x,y]内平衡数的个数. (0 ≤ x ≤ y ≤ 1018) 解法:数位dp.如果一个数的平衡数,那么它的平衡轴位置是确定的.原来一直尝试数位dp在dfs时候列举平衡轴的位置,后来才意识到可以提前枚举平衡轴位置,然后再dfs,这样比较好写.dp[mid][pre][wei];表示对称轴是mid,计算第pre个位置以后需要力矩大小wei的数的个数.

POJ 2761-Feed the dogs(划分树)求区间内第k小的数

Feed the dogs Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 17679   Accepted: 5561 Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs every day for Wind. Jiajia loves Wind, but not the

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

杭电ACM3415——Max Sum of Max-K-sub-sequence

一开始,看到这题,以为是最大连续子序列和的问题,写出了代码,提交了,WR,找了一些测试数据,结果发现这个算法并不能将所以的序列的解求出,只是满足一部分序列. 百度了一下,知道了要用单调队列来求解. 单调队列,也就是队列中必然是单调递减的或者递增的.而这题使用的是单调递增的队列. 单调队列使用的是双向队列,队尾队头都可以删除元素,只能从队尾插入元素. 比如求解一个数列{1  ,2  ,5 ,3, 4, 6}的最长的递增序列的长度. 首先,1入队,队列中有 1. 接下来2比1 大,2入队,队列为 1

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

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