Problem Description



Giving the N, can you tell me the answer of F(N)?

Input

Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed.

Output

For each test case, output on a line the value of the F(N)%2009.

Sample Input

1

2

3

0

Sample Output

1

7

20

一般这种让根据公式求出对应项的值得题都有规律 (有一个循环,此题的循环为4018(注意 这种有循环规律的是让你输出对应项对某个数取余后的题))可以先打表写出有限个数的结果,再观察规律,或者直接写代码判断是否进入了循环。

import java.math.BigDecimal;
import java.util.Scanner; public class Main {
static int[] f = new int[10000];
public static void main(String[] args) {
f[1]=1;
f[2]=7;
for(int i=3;i<=4018;i++){
f[i] = (f[i-2]-((i-1)*(i-1)*(i-1))+(i*i*i))%2009;
//System.out.println(i+" "+f[i]);
}
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
if(n==0)
return ;
// for(int i=3;i<100000;i+=2){
// if(f[i]==1&&f[i+1]==7){
// System.out.println(i-1);
// break;
// }
// }
//判断多久开始循环
System.out.println(f[n%4018]);
} } }

HDOJ 2802 F(N)的更多相关文章

  1. hdoj 2802 F(N)【递推 规律】

    F(N) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. 【HDOJ】2802 F(N)

    找循环节水题.注意余数大于0. /* 2802 */ #include <cstdio> #include <cstring> #include <cstdlib> ...

  3. HDOJ 4734 F(x)

    数位DP.... F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  4. HDU 2802 F(N) 数论+打表

    题目大意:f[n]-n^3=f[n-2]-(n-1)^3 (n >=3),f[1]=1,f[2]=7,求f[n]. 题目思路:将n^3移到到等式右边化简的到:f[n]=f[n-2]+3n*(n- ...

  5. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. HDU - 2802 F(N) (周期)

    题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #incl ...

  7. HDOJ 2582 f(n)

    Discription This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+… ...

  8. 数学--数论--HDU 2802 F(N) 公式推导或矩阵快速幂

    Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1 ...

  9. F(N)---hdu2802(寻找循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2802 f[1] = 1; f[2] = 7; f[n] = (f[n-2] - (n-1)*(n-1) ...

随机推荐

  1. Java使用poi对Execl简单_写_操作

    public class WriteExecl { @Test public void writeExeclTest() throws Exception{ OutputStream os = new ...

  2. linux下启动oracle服务命令

    以redflag(redhat /centos)linux下的 oracle 10g 为例: 如果oracle安装和配置都没有问题的话: 依次执行以下代码即可启动oracle服务. #su - ora ...

  3. oc常用正则表达式

    常用的第三方正则库: http://regexkit.sourceforge.net/RegexKitLite/index.html 匹配中文字符的正则表达式: [\u4e00-\u9fa5]评注:匹 ...

  4. JSONModel的基本使用

    JSONModel 是一个库,它能智能并且快速的创建出数据 model,你可以在你的 iOS 项目或者 OSX 项目上使用它. 使用前准备 添加 JSONModel 到你的工程中 1.需要的环境: A ...

  5. Uploadify 笔记分享 -- 2014年10月18日

    最近要做一个项目,有个部分需要用到Uploadify,以前用过,但不是很懂,找了无数遍的中文文档,发现好多都是以前的,都不能用,一时间索性自己写了个笔记,随用随查 <form> <i ...

  6. Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)

    方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...

  7. 代码bug

    1.webstorm ide未配置basePath本地会加入根路径 2.点击一次就销毁可以给标签设置一个值data-val="0" 某个函数只执行一次的方法,或者也可以考虑绑用on ...

  8. DedeCMS时间格式

    时间格式 {dede:field name='pubdate' function='strftime("%Y年%m月%d日 %H:%M:%S","@me")' ...

  9. ajax xmlhttprequest status

    status 0**:未被始化 status 1**:请求收到,继续处理 status 2**:操作成功收到,分析.接受 status 3**:完成此请求必须进一步处理 status 4**:请求包含 ...

  10. sphinx(coreseek)——1、增量索引

    首先介绍一下     CoreSeek/Sphinx的发布包 indexer: 用于创建全文索引;    search: 一个简单的命令行(CLI) 的测试程序,用于测试全文索引;    search ...