F (N)
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4078 Accepted Submission (s): 1432
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 Input1230
Sample Output1720 General This lets according to the formula to find the corresponding item is worth the law (there is a loop, the loop of the problem is 4018 (note that this has a cyclic law is to let you output the corresponding item to a number after the problem)) can first hit the table to write a finite number of results, and then observe the law
#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #define LL Long Long#define MAX 10010using namespace std; LL S[max]; LL p[max];void Biao () {int i,j;s[1]=p[1]=1;s[2]=p[2]=7;for (i=3;i<=4020;i++) {S[i]=s[i-2]+pow (i,3)-pow ((i-1), 3);p [I]=s[i]%2009;}} int main () {int N,m,i,j;biao (), while (scanf ("%d", &n), N) {printf ("%lld\n", p[n%4018]);} return 0;}
Hdoj 2802 F (N) "Recursive law"