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. 浏览器User-agent简史(user-agent)

    In the beginning there was NCSA Mosaic, and Mosaic called itself NCSA_Mosaic/2.0 (Windows 3.1), and ...

  2. Slate中绑定动态数据

    https://answers.unrealengine.com/questions/232322/slate-blurred-border-shadow.html

  3. Leetcode Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  4. MongoDB使用小结:一些不常见的经验分享

    最近一年忙碌于数据处理相关的工作,跟MongoDB打交道极多,以下为实践过程中的Q&A,后续会不定期更新补充. 另有<MongoDB使用小结:一些常用操作分享>,注:本文完成时Mo ...

  5. Spring-AOP面向切面编程

    AOP是面向切面编程,区别于oop,面向对象,一个是横向的,一个是纵向. 主要解决代码分散和混乱的问题. 1.概念: 切面:实现AOP共有的类 通知:切面类中实现切面功能的方法 连接点:程序被通知的特 ...

  6. Unity学习疑问记录之触屏

    当将Unity游戏运行到ios或android设备上时,桌面系统中的鼠标左键操作可以自动变为手机屏幕上的触屏操作,但鼠标操作无法实现一些特有的触屏操作,比如多点触屏. 触控对于Android移动设备来 ...

  7. java list去重

    1.不带类型写法: 1 List listWithoutDup = new ArrayList(new HashSet(listWithDup)); 2.带类型写法(以String类型为例):1)Ja ...

  8. NDK中可靠的获取JNIEnv*的方法

    使用NDK时,几乎任何方法都需要一个JNIEnv来调用.这个类是和线程相关的,如何可靠的获取它? 首先,作为NDK的so,必然有一个地方是由android系统调用的,这个调用将带来一个JNIEnv参数 ...

  9. 掌握Thinkphp3.2.0----模型初步

    1.为什么要学习框架?框架是什么? 简单的说就是为了简单,提高开发的效率.至于什么是框架(一种规范),现在的我还不是很理解,容后再议. 学习框架最重要的就是遵循,按照开发者的意图来使用该框架. 2.t ...

  10. MySQL触发器使用详解

    MySQL包含对触发器的支持.触发器是一种与表操作有关的数据库对象,当触发器所在表上出现指定事件时,将调用该对象,即表的操作事件触发表上的触发器的执行. 创建触发器在MySQL中,创建触发器语法如下: ...