Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void print(long long int last,long long int start)
- {
- cout<<start++;
- for(int x=start;x<=last;x++)
- {
- cout<<"+"<<x;
- }
- }
- void findconsecutive(long long int n)
- {
- for(int last=1;last<n;last++)
- {
- for(int start=0;start<last;start++)
- {
- if(2*n==(last-start)*(last+start+1))
- {
- cout<<n<<" = ";
- print(last,start+1);
- return;
- }
- }
- }
- cout<<"IMPOSSIBLE";
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- long long int n;
- cin>>n;
- findconsecutive(n);
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement