数学_大数求模(HDU_1021)

公式: (a+b)%k = (a%k + b%k)%k

    (a-b)%k = (a%k - b%k)%k

#include <stdio.h>
#include <string.h>

#define M 1000000
#define MOD 3

int map[M] = {7,11};

void init()
{
    for(int i=2; i<M; i++)
    {
        map[i] = (map[i-2] % MOD + map[i-1] % MOD) % MOD;
    }
}

int main(int argc, char* argv[])
{
    #ifdef __MYLOCAL
    freopen("in.txt","r",stdin);
    #endif

    int n;
    init();
    while(scanf("%d",&n) != EOF)
    {
        printf("%s\n",map[n]%MOD == 0 ? "yes" : "no");
    }

    return 0;
}

 

posted on 2013-07-31 19:39  lk1993  阅读(170)  评论(0编辑  收藏  举报