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

  

最新文章

  1. java的反射机制
  2. mysql 数据库怎样快速的复制表以及表中的数据
  3. MongoDB学习(1)—在Windows系统中安装MongoDB
  4. [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
  5. cf.295.B Two Buttons (bfs)
  6. Using self-defined Parcelable objects during an Android AIDL RPC / IPC call
  7. Java Bean validation specification...
  8. Jquery学习(三)选择
  9. 关于php中的include html文件的问题,为什么html可以在php中执行
  10. WINDOWS java 不能正常卸载 问题, (其他系统问题 也可以试试)
  11. 非vue-cli的花括号闪现问题
  12. Nginx模块开发与架构解析(nginx安装、配置说明)
  13. I - A/B
  14. axios post、get 请求参数和headers配置
  15. spring笔记-@Primary注解
  16. MYSQL错误:You can&#39;t specify target table for update in FROM clause
  17. Git_解决冲突
  18. [翻译] AGPhotoBrowser 好用的图片浏览器
  19. Hive常见问题
  20. Jsonp实现Ajax跨域Demo

热门文章

  1. CAT 安装运行配置教程
  2. 网站用户行为分析——在Ubuntu下安装MySQL及其常用操作
  3. STM32JTAG口用作普通IO的配置
  4. 用JavaScript动态实现单元格合并
  5. python类的封装
  6. 【blockly教程】第五章 循环结构
  7. Ubuntu 安装 搜狗输入法
  8. java 类装饰
  9. python版protobuf 安装
  10. katalon系列五:使用Katalon Studio手动编写WEB自动化脚本