F(N)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5026 Accepted Submission(s): 1788
Giving the N, can you tell me the answer of F(N)?
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long f[110000];
void init()
{
int i;
f[1]=1;
f[2]=7;
for(i=3;i<=5000;i++)
f[i]=(f[i-2]+3*i*i-3*i+1)%2009;
}
int main()
{
long long n,i;
init();
while(scanf("%lld",&n),n)
{
//for(i=3;i<=110000;i=i+2)打表法找出循環節
//if(f[i]==1)
//break;
//printf("%I64d\n",i-1);
//for(i=4;i<=110000;i=i+2)
//if(f[i]==7)
//break;
//printf("%I64d\n",i-2);
//printf("%I64d\n",f[4018]);
printf("%lld\n",f[n%4018]);
}
return 0;
}