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+……+ 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

Author

wangye

Source

HDU 2007-11 Programming Contest_WarmUp

题目大意:给你一个奇数N,求1~N中奇数的平方和。

思路:直接暴力超时了,所以用公式来做 S = N*(N+1)*(N+2)/6,因为结果不超int型,

但是中间过程会超一些,所以用__int64来做就可以了。注意cin、cout会超时,用scanf

和printf就可以了。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    __int64 N,sum;
    while(~scanf("%I64d",&N))
    {
        sum = 0;
        sum = N*(N+1)*(N+2)/6;
        printf("%I64d\n",sum);
    }

    return 0;
}
时间: 2024-10-16 18:56:00

HDU2139 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

Codeforces Gym 100610 Problem E. Explicit Formula 水题

Problem E. Explicit Formula Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Consider 10 Boolean variables x1, x2, x3, x4, x5, x6, x7, x8, x9, and x10. Consider all pairs and triplets of distinct variables amon

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

水题/hdu 1012 u Calculate e

题意 求n=0~9时的sigma(1/n!) 分析 因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题 Accepted Code 1 /* 2 PROBLEM:hdu 1012 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 #include<iostream> 7 #include<iomanip> 8 using namespace std; 9 double a[10]; 10 int main() 11 { 12 cout<&l

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

hdu-5804 Price List(水题)

题目链接: Price List Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 K (Java/Others) Problem Description There are n shops numbered with successive integers from 1 to n in Byteland. Every shop sells only one kind of goods, and the

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

poj2478 欧拉函数水题

poj2478 欧拉函数水题 Y - Farey Sequence Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2478 Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational number

HDU 1800 Flying to the Mars (水题)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11099    Accepted Submission(s): 3572 Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the popul