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. ArrayList数组列表

    ArrayList数组列表 Collection接口和List接口的区别 List接口扩充了Collection接口,添加了索引相关的方法. code example Object get(int i ...

  2. Linux 查杀病毒的常见命令

    1. 查看异常连接的网络端口及其对应的相应的进程 netstat -anlp | grep EST 2.看下相关的进程ID对应的可执行文件的位置 ps 2393 可以看到进程的可执行文件在哪? 3.临 ...

  3. php 正则 常用基础

    正则表达式 用来描述一串字符串的字符串 定界符 除了字母数字反斜线之外的所有字符都可以 / / (强制使用) | | !! 原子 在自然界中的最小单位 叫做原子 正则中的原子:可以打印的字母,数字,符 ...

  4. 【BZOJ】3930: [CQOI2015]选数

    题意 从区间\([L, R]\)选\(N\)个数(可以重复),问这\(N\)个数的最大公约数是\(K\)的方案数.(\(1 \le N, K \le 10^9, 1 \le L \le R \le 1 ...

  5. html5和css3学习笔记

    HTML5针对移动端,移动端的浏览器主要是chrome,是webkit内核; app(applicatin):应用; native app:原生的app sadsadsadad 单标签可以省略结尾标记 ...

  6. Daily Scrum02 12.07

    最近大家都在赶编译的大作业,没日没夜的码代码,调试,大家都很辛苦,但是,我们团队的工作,大家也不能懈怠啊! 大家要顶住压力,加油努力啊! Member 任务进度 下一步工作 吴文会 就总结点进行汇报 ...

  7. java并发编程(三)线程挂起,恢复和终止的正确方法

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17095733    下面我们给出不用上述两个方法来实现线程挂起和恢复的策略--设置标志位. ...

  8. Hyper-V~双网卡设置

    Windows: Win10 有线网卡+无线网卡各一块 Hyper-V: 10.0.10240.16384 公司网络服务器180网段,公网192.168.0.*网段 家里网络:192.168.1.*网 ...

  9. js 事件大全

    Js事件大全一般事件 事件 浏览器支持 描述onClick IE3|N2|O3 鼠标点击事件,多用在某个对象控制的范围内的鼠标点击onDblClick IE4|N4|O 鼠标双击事件onMouseDo ...

  10. 兼容iOS 10 资料整理笔记

    原文链接:http://www.jianshu.com/p/0cc7aad638d9 1.Notification(通知) 自从Notification被引入之后,苹果就不断的更新优化,但这些更新优化 ...