2022-02-12 02:08:28 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using std::cin;
|
|
|
|
|
using std::cout;
|
2024-07-13 14:57:59 +00:00
|
|
|
|
const char endl = '\n';
|
2022-02-12 02:08:28 +00:00
|
|
|
|
|
2024-07-13 14:57:59 +00:00
|
|
|
|
int m;
|
2022-02-12 02:08:28 +00:00
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
std::ios::sync_with_stdio(false);
|
2024-07-13 14:57:59 +00:00
|
|
|
|
cin.tie(nullptr);
|
|
|
|
|
|
2022-02-12 02:08:28 +00:00
|
|
|
|
cin >> m;
|
2024-07-13 14:57:59 +00:00
|
|
|
|
|
|
|
|
|
// 为什么到 m/2 结束?因为 m/2 之后的数不可能连着取两个数之和等于 m。
|
|
|
|
|
for (int i = 1, j = 2, sum = 3 /* 初始 1 + 2 = 3 */; i <= (m >> 1);) {
|
|
|
|
|
if (sum == m) { // 够了,输出答案,并且把左面的数从窗口中删去
|
2022-02-12 02:08:28 +00:00
|
|
|
|
cout << i << ' ' << j << endl;
|
2024-07-13 14:57:59 +00:00
|
|
|
|
sum -= i++; // 压行:sum -= i; i++;
|
|
|
|
|
} else if (sum < m) { // 不够,需要往后再取一个数
|
|
|
|
|
sum += ++j; // 压行:j++; sum += j; # 注意:这里是先加 j 再加 sum,顺序要写对
|
|
|
|
|
} else { // sum > m # 多了,把左面的数从窗口中删去
|
|
|
|
|
sum -= i++; // 压行:sum -= i; i++;
|
2022-02-12 02:08:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 14:57:59 +00:00
|
|
|
|
|
2022-02-12 02:08:28 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|