模拟_预处理(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
",map[n]);
    }

    return 0;
}
原文地址:https://www.cnblogs.com/lk1993/p/3228466.html