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. c#冒泡排序算法和快速排序算法

    依次比较相邻的两个数,将小数放在前面,大数放在后面. 第1趟: 首先比较第1个和第2个数,将小数放前,大数放后.然后比较第2个数和第3个数,将小数放前,大数放后,如此继续,直至比较最后两个数,将小数放 ...

  2. Webpack4 学习笔记八 开发环境和生产环境配置

    webpack resolve属性 webpack 区分开发环境和生产环境 webpack resolve属性 该选项的作用是设置模块如何被解析. resolve.alias: 设置别名, 在vue中 ...

  3. React中需要多个倒计时的问题

    最近有一个需求是做一个闪购列表,列表中每一个商品都有倒计时,如果每一个倒计时都去生成一个setTimeout的话,一个页面就会有很多定时器,感觉这种做法不是非常好,于是换了一个思路. 思路是这样的,一 ...

  4. ABAP术语-Method

    Method 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/05/1091077.html Component of classes in ...

  5. 使用Linux命名将代码上传到GitHub

    GitHub代码上传教程 https://my.oschina.net/baishi/blog/520791 这篇文章讲得挺清楚的,但是在上传的时候出现了问题 ! [rejected] master ...

  6. InheritableThreadLocal线程复用

    引自:http://www.cnblogs.com/sweetchildomine/p/6575666.html 虽然使用AOP可以获取方法签名,但是如果要获取方法中计算得出的数据,那么就得使用Thr ...

  7. 字符编码 ASCII unicode UTF-8

    字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节(b ...

  8. ThinkPHP框架介绍

    什么是框架 php框架是许多代码的集合,这些代码的程序结构的代码(并不是业务代码)代码中有许多的函数,类,功能类包 不使用框架开发的缺陷 代码编写不规范 牵一发而动全身 不能很好满足客户各方面的需求 ...

  9. hive的desc命令

    desc命令 desc 命令是为了展示hive表格的内在属性.例如列名,data_type,存储位置等信息.这个命令常常用在我们对hive表格观察之时,我们想要知道这个hive各个列名(基于这些具体列 ...

  10. Spark是什么

    官方直达电梯 Spark一种基于内存的通用的实时大数据计算框架(作为MapReduce的另一个更优秀的可选的方案) 通用:Spark Core 用于离线计算,Spark SQL 用于交互式查询,Spa ...