hdu-2082-F(N)

来源:互联网 发布:网络固定电话怎么装 编辑:程序博客网 时间:2024/06/06 08:49
【科普】什么是BestCoder?如何参加?

F(N)

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3546 Accepted Submission(s): 1220


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
0
3

Sample Output
1
7
2
0
#include<stdio.h>int a[4020]={0,1,7};int main(){    int n,i;    for(i=3;i<4020;i++)    {        a[i]=(a[i-2]-(i-1)*(i-1)*(i-1)+i*i*i)%2009;    }    while(scanf("%d",&n)&&n)        printf("%d\n",a[n%4018]%2009);    return 0;}



0 0
原创粉丝点击