HDU 2139 Calculate the formula

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;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9686151.html

时间: 2024-10-10 12:56:46

HDU 2139 Calculate the formula的相关文章

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

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,Java就是打表,都不能AC,因为Java的输入是流,需要的时间比C真的长好多.... Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+--+ n ^2. Input In each

HDU2139 Calculate the formula【水题】

Calculate the formula Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7441    Accepted Submission(s): 2284 Problem Description You just need to calculate the sum of the formula: 1^2+3^2+5^2+--+

HDU 2114 Calculate S(n)(公式)

Calculate S(n) Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9640    Accepted Submission(s): 3492 Problem Description Calculate S(n). S(n)=13+23 +33 +......+n3 . Input Each line will contain

Calculate the formula

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 用普通的做法

J - Calculate the formula

You just need to calculate the sum of the formula: 1^2+3^2+5^2+--+ n ^2. InputIn each case, there is an odd positive integer n.OutputPrint the sum. Make sure the sum will not exceed 2^31-1Sample Input 3 Sample Output 10代码如下: (不过还是建议大家看看下面的错误代码和思路)#in

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

传送门 题意:从输入开始,1.输入样例数:2.然后输入一组样例中的行数n:3.前n-1行为定义变量(之间使用空格隔开),只需要map存进去就可以了(这里有覆盖的情况,故使用mp["s"] = "***"的方法赋值,因为insert的方法如果里面存在的话,插不进入数值):4.然后就是最后一行输入计算式子(之间使用空格隔开). 思路:我使用的字符流的方法分割的的字符串,因为题中说了使用空格隔开的: 变量的储存使用map就可以,在最后一行输入计算式子之后,同样使用字符流分

HDU - 2114 Calculate S(n)

1 #include <bits/stdc++.h> 2 #define _xx ios_base::sync_with_stdio(0);cin.tie(0); 3 #define INFS 0x3fffffff 4 #define INFB 0x3fffffffffffffff 5 #define pf printf 6 #define sf scanf 7 #define mem(a, b) memset(a, 0, sizeof a); 8 using namespace std; 9

hdu 6217 A BBP Formula 公式题

https://zh.wikipedia.org/wiki/%E8%B4%9D%E5%88%A9-%E6%B3%A2%E5%B0%94%E6%B8%A9-%E6%99%AE%E5%8A%B3%E5%A4%AB%E5%85%AC%E5%BC%8F http://blog.csdn.net/meopass/article/details/78327614 这类公式是用来求解一些无理数常数的公式,特点是不需要求解前n-1位也能去算第n位 假设你得到了PI,那么你求十六进制下第n位,只需要把在16进制下

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

History repeat itself Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 434264-bit integer IO format: %I64d      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None None Graph Theory 2-S