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个数立方和。

所以可以选择打表(不知道立方和的公式,可以选择打表)。

立方和公式:1^3+2^3+3^3+4^3+...+n^3 = (n*(n+1)/2)^2

AC代码:

这里是是打表的思路

 #include<stdio.h>
#include<string.h> typedef long long LL; const LL MAXN = ; int main(){
int T, A, B;
LL ans, a[MAXN]; memset(a, , sizeof(a));
for(LL i = ; i < MAXN; ++i){
a[i] = a[i - ] + i * i * i;
} scanf("%d", &T);
for(int cs = ; cs <= T; ++cs){
scanf("%d%d", &A, &B); printf("Case #%d: %I64d\n", cs, a[B] - a[A - ]);
}
return ;
}

利用公式:

 #include<stdio.h>
#include<string.h> typedef long long LL; LL f(LL n){
return n * (n + ) * n * (n + ) / ;
} int main(){
int T, A, B;
scanf("%d", &T);
for(int cs = ; cs <= T; ++cs){
scanf("%d%d", &A, &B);
printf("Case #%d: %I64d\n", cs, f(B) - f(A - ));
}
return ;
}

HDU 5053 the Sum of Cube(简单数论)的更多相关文章

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

    the Sum of Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 5053 the Sum of Cube

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053 解题报告:用来陶冶情操的题,求a到b的三次方的和. #include<stdio.h> ...

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

    水 #include <stdio.h> #include <stdlib.h> #include<math.h> #include<iostream> ...

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

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

  5. HDU 1024 Max Sum Plus Plus 简单DP

    这题的意思就是取m个连续的区间,使它们的和最大,下面就是建立状态转移方程 dp[i][j]表示已经有 i 个区间,最后一个区间的末尾是a[j] 那么dp[i][j]=max(dp[i][j-1]+a[ ...

  6. hdu 2058 The sum problem(简单因式分解,,)

    Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-se ...

  7. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

  8. 七夕节 (HDU - 1215) 【简单数论】【找因数】

    七夕节 (HDU - 1215) [简单数论][找因数] 标签: 入门讲座题解 数论 题目描述 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们 ...

  9. (step7.2.1)hdu 1395(2^x mod n = 1——简单数论)

    题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == ...

随机推荐

  1. JVM中对象的创建过程

    JVM中对象的创建过程如以下流程图中所示: 对其主要步骤进行详细阐述: 为新生对象分配内存: 内存的分配方式: 指针碰撞:假设Java堆中内存是绝对规整的,所有用过的内存放在一边,空闲的内存在另一边, ...

  2. maven模块

    用maven无它,唯方便而. 模块依赖可以用来做一些公共模块,多个工程调用. 先子模块 install 或者package.在父模块install

  3. java内置数据类型

    常量在程序运行时,不会被修改的量. 在 Java 中使用 final 关键字来修饰常量,声明方式和变量类似: finaldouble PI =3.1415927; 虽然常量名也可以用小写,但为了便于识 ...

  4. php 截取中文字符串 - ord()函数 0xa0...

    在ASCII中,0xa0表示汉字的开始 其中php中的一个函数ord()函数 此函数功能返回一个字符的askii码值: 如ord('A')=65; <?php function GBsubstr ...

  5. 【转】WiFi基础知识

    http://blog.csdn.net/myarrow/article/details/7930131 1. IE802.11简介 标准号 IEEE 802.11b IEEE 802.11a IEE ...

  6. Thread-Safe Resource Manager

    http://php.net/manual/en/internals2.memory.tsrm.php When PHP is built with Thread Safety enabled, th ...

  7. Codevs 3728 联合权值

    问题描述 无向连通图G有n个点,n-1条边.点从1到n依次编号,编号为i的点的权值为Wi ,每 条边的长度均为1.图上两点(u,v)的距离定义为u点到v点的最短距离.对于图G上的点 对(u,v),若它 ...

  8. 数据库的修改和删除;比较标签代替<,>,=号;模板替换;session的用法

    注: 1.session:系统默认开启;用途:防止跳过登录(只能访问登录方法);session和cookie的用法(手册->专题); 赋值:session('name','value'); 取值 ...

  9. CodeForces 676D代码 哪里有问题呢?

    题目: http://codeforces.com/problemset/problem/676/D code: #include <stdio.h> #define MAXN 1001 ...

  10. Python先合并再排序

    前几天遇到的美团笔试题 题目:大概要求输入两组数字,对这两组数值排序然后输出结果 思路:输入两组数,合并两组数,排序 list1 = raw_input("input some number ...