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 one integer N(1 < n < 1000000000). Process to end of file.

Output

For each case, output the last four dights of S(N) in one line.

Sample Input

1

2

Sample Output

0001

0009

Author

天邪

Source

HDU 2007-10 Programming Contest_WarmUp

 1 //1~N的立方和公式为S(N) = 1^3 + 2^3 + 3^3 + … + N^3 = N^2*(N+1)^2/4
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6 int main()
 7 {
 8     long long n;
 9     long long sum;
10     while(cin>>n){
11         n%=10000;
12         sum=(n*n)*(n+1)*(n+1)/4;
13         sum%=10000;
14         printf("%04lld\n",sum);
15     }
16     return 0;
17 }
时间: 2024-08-08 15:52:14

HDU 2114 Calculate S(n)(公式)的相关文章

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 4952 Number Transformation(公式)

HDU Number Transformation 题目链接 题意:按题目中要求求出最后的n 思路:推公式(i+1)x′>=ix,得到x′>=1+floor(xi+1),这样一来就可以递推x,那么注意题目中k很大,但是实际上如果i到一定数值之后,x就不会在增长了,这时候就可以break了 代码: #include <cstdio> #include <cstring> typedef long long ll; ll n, k; int main() { int cas

hdu 4927 Series 1(组合+公式)

题目链接:hdu 4927 Series 1 题目大意:给定一个长度为n的序列a,每次生成一个新的序列,长度为n-1,新序列b中bi=ai+1?ai,直到序列长度为1.输出最后的数. 解题思路:n最多才3000,ai最大也才1000,貌似不会超int,但是要注意,有些数不止被计算了一次,最多的数被计算了C(15003000),所以肯定要用高精度处理,那么用o(n2)的复杂度肯定就跪了.其实对于最后的ans,ans=∑i=0n?1C(in?1)?ai?(?1)i+1(类似杨辉三角) import

HDU 1018 -- Big Number (Stirling公式求n!的位数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40551    Accepted Submission(s): 19817 Problem Description In many applications ver

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 excee

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

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

hdu 3524 Perfect Squares 推公式求逆元

Perfect Squares Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 501    Accepted Submission(s): 272 Problem Description A number x is called a perfect square if there exists an integer b satisfy

2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9+7; struct Matrix{ LL a[3][3]; void set1(){ memset(a, 0, sizeof(a)); } void set2(){ memset(a, 0, siz

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