蓝桥杯 煤球数目(第七届第一题)


煤球数目

有一堆煤球,堆成三角棱锥形。具体:
第一层放1个,
第二层3个(排列成三角形),
第三层6个(排列成三角形),
第四层10个(排列成三角形),
....
如果一共有100层,共有多少个煤球?

请填表示煤球总数目的数字。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

 

结果:171700

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <sstream>
#include <climits>
using namespace std;
int main(){
//    freopen("input.txt","r",stdin);
    int res=0;
    int sum=0;
    int n=100;
    for(int i=1;i<=n;i++){
        sum+=i;
        res+=sum;
    }
    cout<<res;

}

 

posted @ 2019-03-13 19:57  开局一把刀  阅读(3)  评论(0)    收藏  举报