跳到正文

题解

分苹果

chenxichen约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年5月30日
更新
2026年5月30日
篇幅
约 1 分钟
获赞
1
题目
B2072

版本

  1. v1当前

这题好难我要抄题解
这题其实很简单
我们先分析一手

办法

想要最少且不同
可以1,2,3,4,5,6,7,8,9等 用for语句
这样即不同也最少

Code

#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int cnt = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cnt = cnt + i;
}
cout << cnt << endl;
return 0; }
好长呀
用等差数列公式求解:
Sn=n(n+1)2S_n=\dfrac{n(n+1)}{2}

Code2

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<n*(n+1)/2; return 0;
}
END

原文