HDU 2114 Calculate S(n)
2024-10-19 04:21:23
http://acm.hdu.edu.cn/showproblem.php?pid=2114
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
时间复杂度:$O(n)$
代码:
#include <bits/stdc++.h>
using namespace std; long long a[10010]; long long A(long long x) {
return x * x % 10000 * x % 10000;
} int main() {
long long n, S;
for(int i = 1; i <= 10000; i ++) {
a[i] = (a[i-1] + A(i))%10000;
}
while(~scanf("%lld", &n)) {
printf("%04lld\n", a[ n % 10000]);
}
return 0;
}
最新文章
- java的反射机制
- mysql 数据库怎样快速的复制表以及表中的数据
- MongoDB学习(1)—在Windows系统中安装MongoDB
- [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
- cf.295.B Two Buttons (bfs)
- Using self-defined Parcelable objects during an Android AIDL RPC / IPC call
- Java Bean validation specification...
- Jquery学习(三)选择
- 关于php中的include html文件的问题,为什么html可以在php中执行
- WINDOWS java 不能正常卸载 问题, (其他系统问题 也可以试试)
- 非vue-cli的花括号闪现问题
- Nginx模块开发与架构解析(nginx安装、配置说明)
- I - A/B
- axios post、get 请求参数和headers配置
- spring笔记-@Primary注解
- MYSQL错误:You can&#39;t specify target table for update in FROM clause
- Git_解决冲突
- [翻译] AGPhotoBrowser 好用的图片浏览器
- Hive常见问题
- Jsonp实现Ajax跨域Demo