http://acm.hdu.edu.cn/showproblem.php?pid=2139

Problem Description
You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.
 
Input
In each case, there is an odd positive integer n.
 
Output
Print the sum. Make sure the sum will not exceed 2^31-1
 
Sample Input
3
 
Sample Output
10
 

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 2345;
long long s[maxn]; int main() {
int N;
s[1] = 1;
for(int i = 3; i <= maxn; i += 2)
s[i] = s[i - 2] + i * i; while(~scanf("%d", &N)) {
printf("%lld\n", s[N]);
} return 0;
}

  

HDU 2139 Calculate the formula的更多相关文章

  1. HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...

  2. Calculate the formula

    Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+……+ n ^2.   Input ...

  3. HDU 2114 Calculate S(n)

    http://acm.hdu.edu.cn/showproblem.php?pid=2114 Problem Description Calculate S(n). S(n)=13+23 +33 +. ...

  4. hdu 2114 Calculate S(n) 数论(简单题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114 自己对数论一窍不通啊现在,做了一道水题,贴出来吧...主要是让自己记住这个公式: 前n项和的立方 ...

  5. HDU - 3347 Calculate the expression — 模拟 + map存变量

    传送门 题意:从输入开始,1.输入样例数:2.然后输入一组样例中的行数n:3.前n-1行为定义变量(之间使用空格隔开),只需要map存进去就可以了(这里有覆盖的情况,故使用mp["s&quo ...

  6. hdu 6217 A BBP Formula 公式题

    题意 已知公式:$\pi=\sum_{k=0}^{\infty}\left[\frac{1}{16^{k}}\left(\frac{4}{8 k+1}-\frac{2}{8 k+4}-\frac{1} ...

  7. 【HDU 2855】 Fibonacci Check-up (矩阵乘法)

    Fibonacci Check-up Problem Description Every ALPC has his own alpc-number just like alpc12, alpc55, ...

  8. HDU 4342——History repeat itself——————【数学规律】

    History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  9. HDU 4342History repeat itself 数学

    C - History repeat itself Time Limit:1000MS     Memory Limit:32768KB      Description Tom took the D ...

随机推荐

  1. (mybatis)There is no getter for property named 'isEffective' in 'class java.lang.String

    原来代码: <select id="findSpecialOffer" resultType="com.lizard.back.model.SpecialOffer ...

  2. vue 父子组件相互传值

    子传父 逻辑: 单击子组件的按钮 ,触发它的单击事件   通过 $emit 触发父级自定义事件 并传一个值给父级 <div id="id"> <h3>儿子 ...

  3. java中的基本算法

    整理一下常用的又基础的算法.由于平时的项目比较简单,很少用到算法,但工作不只是眼前的苟且,还有诗和远方. 1.链表 链表用来存储数据,由一系列的结点组成.这些结点的物理地址不一定是连续的,即可能连续, ...

  4. 访问本地方站出现EOF的分析和解决

    每天早晨打开电脑运行本地项目的时候,有时候浏览器上会出现EOF 之前都都能正常访问,所以我猜想本地的项目本身肯定是没有问题的. Google了下,发现有人说是代理的问题,于是关闭代理试过后,发现可以访 ...

  5. Java中Redis缓存

    1:安装 安装可分为单机版redis 和集群版redis  安装比较简单,自行百度即可 2:集成 pom文件中加入jedis 依赖,spring创建redis的application-resid配置, ...

  6. django环境搭建和学习

    由于服务器down了好几天,前几天做的django的project全都在上面,无法继续开展工作,所以决定在本地重新部署一套virtualenv 之前没有好好整理过部署过程(其实也不难),所以决定写个随 ...

  7. 阻塞队列之LinkedBlockingQueue

    概述 LinkedBlockingQueue内部由单链表实现,只能从head取元素,从tail添加元素.添加元素和获取元素都有独立的锁,也就是说LinkedBlockingQueue是读写分离的,读写 ...

  8. 008---re正则模块

    re正则模块 字符串的匹配规则 匹配模式 re.match() re.search() re.findall() re.split() re.sub() 元字符 print('------------ ...

  9. Vee-validate学习

    Vee-validate使用方法 首先引入 <script src="https://cdn.bootcss.com/vee-validate/2.0.9/vee-validate.j ...

  10. Kubernetes-DNS

    Kubernetes提供的虚拟DNS服务名为skydns,由四个组件组成: etcd:DNS存储 kube2sky:将Kubernetes Master中的Service(服务)注册到etcd sky ...