跳到正文

题解

AT2345

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

文章信息

发布
2022年1月7日
收录
2026年10月13日
更新
2026年11月11日
篇幅
约 1 分钟
获赞
1

版本

  1. v1当前

思路:

运用高斯的等差数列

n(n+1)2\frac{n(n+1)}{2} 公式

从一开始,依次套公式,直到那个数套进去的值大于小于目标数,输出套到公式的那个数。

code:

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		i+=ans++;//套公式
	}
	cout<<ans;//输出那个数
	return 0;
}
原文