模拟_预处理(HDU_2132)

注意 i*i*i 会越界,应定义为 __int64

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

#define M 100002

__int64 map[M] = {0,1};

void init()
{
    for(__int64 i=2; i<=100000; i++)
    {
        map[i] = map[i-1] + ((i%3 == 0) ? i*i*i : i);
    }
}

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

    int n;
    init();
    while(scanf("%d",&n) && n>=0)
    {
        printf("%I64d\n",map[n]);
    }

    return 0;
}

 

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