An easy problem

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2132

#include <iostream>
#include <cstdio>
#define ll long long

using namespace std;

const int N = 100005;
ll table[N];
// 打表 , table 和 变量i都要用long long 型,不然要自己转一下
void meter() {
    table[0] = 0;
    for (ll i = 1; i < N; i++) {
        if (i%3==0) table[i] = table[i-1]+i*i*i;// 不用long long 的话,这里会超范围
        else table[i] = table[i-1]+i;
    }
}

int main() {
    int n;
    meter();
    while(~scanf("%d", &n) && n >= 0) {
         // 不能写 n != -1 , 题目原话是 “when n is a negative indicate the end of file.” 
        printf("%lld
", table[n]);
    }
    return 0;
}

。。。。。。。。2020过年闲的蛋疼

原文地址:https://www.cnblogs.com/hello-dummy/p/12298697.html