Skip to content

Instantly share code, notes, and snippets.

@maple3142
Created September 29, 2017 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maple3142/788f13420d8cb6eb2179789613bfeb07 to your computer and use it in GitHub Desktop.
Save maple3142/788f13420d8cb6eb2179789613bfeb07 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
int sum(int a,int b){
return (a+b)*(b-a+1)/2;
}
int main(void){
ios::sync_with_stdio(false);
int n;
while(cin>>n){
int cnt=0;
int s=1,e=1;
while(e<n&&s<=e){
int r=sum(s,e);
if(r==n){
cout<<s<<" "<<e<<endl;
cnt++;
s++;
}
else if(r>n){
s++;
}
else if(r<n){
e++;
}
}
cout<<cnt<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment