F(N) hdu 2802(循环节)

http://acm.hdu.edu.cn/showproblem.php?pid=2802

分析:一猜这道题就该是规律,就是怎么样也没想到周期那么大(4018),我的悲伤比它还大(%>_<%)

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define met(a, b) memset(a, b, sizeof(a))
#define maxn 10000
#define INF 0x3f3f3f3f
const int MOD = 1e9+7;

typedef long long LL;
int a[maxn];

int main()
{
    int n;

    a[1]=1;
    a[2]=7;

    for(int i=3; i<4018; i++)
    {
        a[i]=a[i-2]+3*i*i-3*i+1;
        a[i] %= 2009;
    }

    while(scanf("%d", &n), n)
    {
        n %= 4018;
      printf("%d
",a[n]);
    }

    return 0;
}
View Code
原文地址:https://www.cnblogs.com/daydayupacm/p/5762567.html