Follow link 4018
F (N)Time
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 3542 Accepted Submission (s): 1219
Problem Description
Giving the N, can you tell me the answer of F (N)?
Inputeach 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 is processed.
Outputfor each test case, output in a line the value of the F (N)%2009.
Sample Input
1230
Sample Output
1720
Sourcehdu 2009-4 Programming Contest
/* ***********************************************author : ckbosscreated time : Sunday December 14, 2014 12:29 33 sec File Name : hdoj2802.cpp************************************************ */#include <iostream># Include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map> #include <cmath> using namespace Std;const int mod=2009;int f[5000];int Get (int x) {int part1= ((x*x)%mod*x)%mod;int y=x-1;int part2= ((y*y) %mod*y)%mod;return ((f[x-2]+part1)%mod+mod-part2)%mod;} int main () { //freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout); int n;f[1]=1; f[2]=7;for (int i=3;i<=4018;i++) f[i]=get (i), while (scanf ("%d", &n)!=eof&&n) {n=n%4018;if (n==0) puts (" 0 "); else printf ("%d\n ", F[n]);} return 0;}
Hdoj 2802 F (N)