WA1&3,实在想不出原因
查看原帖
WA1&3,实在想不出原因
918894
XyGetItRightAker楼主2023/12/28 11:28

我的做法是所有和减去3倍的我的房号也等于n。 应该能理解吧。。

循环条件上来讲感觉没什么问题

n最大1e5-1,所以ll也不用的

#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdio.h>
#include<math.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n;
int num[100005];
int main() {
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= 100004; i++) {
		num[i] = num[i - 1] + i;
		if (num[i] >= n) {
			int index = num[i] - n;
			if (index % 3 != 0)continue;
			else {
				ans = index / 3;
				cout << ans << " " << i;
				return 0;
			}


		}
	}




	return 0;
}
2023/12/28 11:28
加载中...