8218 金币数量2

#include<bits/stdc++.h>
#define f(i,s,e) for(int i = s; i <= e; i++)
#define ll long long
using namespace std;
const int N = 1e3+10,inf = 0x3f3f3f3f;

int main()
{
    ll n,sum = 0,g = 0; //n项数有10^6,一直累加会超出int范围,所以用ll 
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        g += i; //金币每层都会加i
        sum += g; //累加金币 
    }
    cout << sum;
    return 0;
}

 

posted @ 2024-06-30 22:49  CRt0729  阅读(1)  评论(0编辑  收藏  举报