P1147 连续正整数和

点击查看代码
#include<bits/stdc++.h>
using namespace std;

int m;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    cin>>m;

    int l=1,r=2;
    int sum=1;

    while(l<=m/2){
        if(sum<m){
            sum+=r;
            r++;
        }else if(sum>m){
            sum-=l;
            l++;
        }else{
            cout<<l<<' '<<r-1<<endl;
            sum-=l;
            l++;
        }
    }

    return 0;
}
posted @ 2026-02-10 20:39  AnoSky  阅读(3)  评论(0)    收藏  举报