酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

巧用滑动窗口:求解给定正整数的连续正整数段之和

```python n = int(input()) # 使用滑动窗口 left, right = 1, 1 current_sum = 0 while left <= n // 2 + 1: if current_sum < n: current_sum += right right += 1 elif current_sum > n: current_sum -= left left += 1 else: print(f"{left} {right - 1}") current_sum -= left left += 1 ``` ######[AI问答 | 107点数解答 | 2026-01-04 12:15:55]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]