当前位置:网站首页>结果填空 煤球数目
结果填空 煤球数目
2022-07-28 05:19:00 【小白鼠零号】
有一堆煤球,堆成三角棱锥形。具体:
第一层放1个,
第二层3个(排列成三角形),
第三层6个(排列成三角形),
第四层10个(排列成三角形),
....
如果一共有100层,共有多少个煤球?
请填表示煤球总数目的数字。
答案
171700
解题过程
明确题目求的是1~100层煤球的总和,那么这种题目肯定有规律。这里分析了每层煤球数目的规律:
第一层:1
第二层:1+2
第三层:1+2+3
第四层:1+2+3+4
……
第一百层:1+2+……+100
很明显每层的数目是个等差数列,等差数列公式:Sn=(a1+an)*n/2
附上代码
#include<iostream>
using namespace std;
int main()
{
int sum=0;
int n;
cin>>n;
for(int i=1;i<=n;i++)
sum+=(1+i)*i/2;
cout<<sum<<endl;
return 0;
}
边栏推荐
- Openjudge: find all substring positions
- SVG了解与绘图应用
- TopK问题
- Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade
- 环形链表问题
- Openjudge: count the number of numeric characters
- Invalid bound statement (not found): com.exam.mapper.UserMapper.findbyid
- DOM——事件
- shell运行原理
- C语言回顾(指针篇)
猜你喜欢
随机推荐
openjudge:找第一个只出现一次的字符
设置滚动条
Custom JSON return data
new,let,var,const以及暂时性死区,xml和json的区别
Docker deploy mysql5.7.35
三大缓存技术--localStorage、sessionStorage、Cookie
Mutual conversion between latex and word
Openjudge: perpetual calendar
Review of metallurgical physical chemistry -- cathodic polarization, overpotential, anode and anode process in metal electrodeposition
uni-app-双击事件模拟
Thesis writing function words
Canvas绘图1
C语言回顾(可变参数篇)
js数据类型检测与修改检测
JS字符串方法大全
A file upload tool website written by individuals
uniapp-监听app是否有网络连接
【uni-app】uni-app中scroll-into-view的使用
openjudge:判断字符串是否为回文
基于Easy CHM和VS的帮助文档制作









