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): 162    Accepted Submission(s): 101

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

1^3+2^3+4^3.....+n^3=(n*(n+1)/2)^2

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 using namespace std;
 6
 7 int main()
 8 {
 9   int cas;
10  __int64 a,b;
11  scanf("%d",&cas);
12  for(int i=1;i<=cas;i++)
13  {
14      scanf("%I64d%I64d",&a,&b);
15      printf("Case #%d: %I64d\n",i,(b*(b+1)/2)*(b*(b+1)/2)-(a*(a-1)/2)*(a*(a-1)/2));
16  }
17  return 0;
18 }

时间: 2024-08-08 22:09:44

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

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

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

hdu 4828 Xor Sum (trie 树模板题,经典应用)

hdu 4825 题目链接 题意:给定n个数,然后给出m个询问,每组询问一个数x,问n中的数y使得x和y的异或和最大. 思路:字典树..把每个数转化成二进制,注意补全前导0,使得所有数都有相同的位数. 如果想要异或和最大,那么每一位尽可能都是1. 所以做法是,先构建字典树,然后每次find的时候,尽可能按照和当前寻找的数的位相反的位的方向走(如果有的话) 比如当前位是1,那我就往0的方向走. 需要注意的是,多组数据,每次要重新初始化一遍. 做法是 在struct 中重新 root = new N

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

HDU5053the Sum of Cube(水题)

题目链接 题目大意:给你L到N的范围,要求你求这个范围内的所有整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出. 代码: #include <cstdio> #include <cstring> const int N = 10005; typedef long long ll; ll t[N]; void init () { for (ll i = 1; i <= N - 5; i++) t[i] = i * i * i; } int m