HDOJ 2114 Calculate S(n)(找周期)
Problem Description
Calculate S(n).
S(n)=1^3+2^3 +3^3 +……+n^3 .
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
题意是:给一个数n,求S(n)=1^3+2^3 +3^3 +……+n^3 .输出最后4位数字,不足4位的补零输出。
如果没找出周期会超时的。
我找到的是以10000为周期。
import java.util.Scanner;
//10000为周期
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int sum =0;
int t;
n = n%10000;
for(int i=1;i<=n;i++){
sum = ((sum)%10000+(((i)%10000)*((i)%10000))%10000*((i)%10000))%10000;
}
if(sum<10){
System.out.println("000"+sum);
}else if(sum<100){
System.out.println("00"+sum);
}else if(sum<1000){
System.out.println("0"+sum);
}else{
System.out.println(sum);
}
}
}
}
HDOJ 2114 Calculate S(n)(找周期)的更多相关文章
- What day is that day?(快速幂,打表找周期,或者求通项公式)
有些题怎么都解不出来,这时候可以打表,找规律,求通项公式等,这些方法让人拍手叫绝,真不错…… Description It's Saturday today, what day is it after ...
- A - Number Sequence(矩阵快速幂或者找周期)
Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * ...
- HDU 2114 Calculate S(n)
http://acm.hdu.edu.cn/showproblem.php?pid=2114 Problem Description Calculate S(n). S(n)=13+23 +33 +. ...
- hdu 2114 Calculate S(n) 数论(简单题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2114 自己对数论一窍不通啊现在,做了一道水题,贴出来吧...主要是让自己记住这个公式: 前n项和的立方 ...
- MT【104】高斯函数找周期
分析:$t(n)=n-[\frac{n}{2}]-[\frac{n}{3}]-[\frac{n}{6}]$的周期为6,故 $\sum\limits_{n=1}^{2014}(n-t(n))=\sum\ ...
- Number Sequence(周期是336!!不是48!!)
1005 Number Sequence 时间限制: 1 Sec 内存限制: 60 MB 题目描述 A number sequence is defined as follows: f(1) = 1 ...
- 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用
转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...
- 【ZOJ】3785 What day is that day? ——KMP 暴力打表找规律
转自:http://www.cnblogs.com/kevince/p/3887827.html 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这么一说大家心里肯定有数了吧,“不就是nex ...
- 51nod 1126 求递推序列的第N项 && hdu - 1005 Number Sequence (求周期)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126 http://acm.hdu.edu.cn/showproblem ...
随机推荐
- [转] Linux TCP/IP网络小课堂:net-tools与iproute2大比较
PS:netstat选项是-planet,方便记忆 http://os.51cto.com/art/201409/450886.htm 如今许多系统管理员仍结合使用ifconfig.route.arp ...
- 连接管理VMware SphereESXi
连接管理VMware SphereESXi 1. 准备 下载VMware-viclient-all-5.5.0-1993072,并按照提示安装 2. 使用VMware Sphere Client链接事 ...
- BeanFactory学习
关于BeanFactory,一个相对易懂的博客,关于深入的理解,后续继续学习 http://www.cnblogs.com/liuling/archive/2013/04/14/BeanFactory ...
- Django Errors Archive
记录使用 Django 开发中遇到的问题,备用 1. 版本要选好,最好安装上 pip,可以省很多麻烦 2. 如果使用 Postgresql,选 8.1 之后的版本,免去 Retruning 之类的错误 ...
- 【转】 iOS使用AVFoundation实现二维码扫描
原文:http://strivingboy.github.io/blog/2014/11/08/scan-qrcode/ 关于二维码扫描有不少优秀第三方库如: ZBar SDK 里面有详细的文档,相应 ...
- JavaScript--垃圾回收器
垃圾回收: 释放不再被任何变量引用的对象 垃圾回收器: 专门记录对象的引用次数,并回收不再被引用的对象的程序. 垃圾回收器和主程序并行在后台执行 垃圾回收器会为每个对象创建一个引用计数器(counte ...
- Android入门随记
1.Activity是通过startActivity()开始的,结束后不反回任何结果,而用startActivityForResult(Intent intent, int resquestCode) ...
- 【BZOJ1010】玩具装箱
Description P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1... ...
- 【USACO 1.3.3】回文串
[題目描述] 据说如果你给无限只母牛和无限台巨型便携式电脑(有非常大的键盘),那么母牛们会制造出世上最棒的回文.你的工作就是去寻找这些牛制造的奇观(最棒的回文). 在寻找回文时不用理睬那些标点符号.空 ...
- (转)Android Studio系列教程一下载与安装 背景Android Studio VS Eclipse准备下载创建HelloWorld项目
背景 相信大家对Android Studio已经不陌生了,Android Studio是Google于2013 I/O大会针对Android开发推出的新的开发工具,目前很多开源项目都已经在采用,Goo ...