Advertisement
happyguy89

Team10

Jul 3rd, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. void print(long long int last,long long int start)
  4. {
  5. cout<<start++;
  6. for(int x=start;x<=last;x++)
  7. {
  8. cout<<"+"<<x;
  9. }
  10. }
  11. void findconsecutive(long long int n)
  12. {
  13. for(int last=1;last<n;last++)
  14. {
  15. for(int start=0;start<last;start++)
  16. {
  17. if(2*n==(last-start)*(last+start+1))
  18. {
  19. cout<<n<<" = ";
  20. print(last,start+1);
  21. return;
  22. }
  23. }
  24. }
  25. cout<<"IMPOSSIBLE";
  26. }
  27. int main()
  28. {
  29. int t;
  30. cin>>t;
  31. while(t--)
  32. {
  33. long long int n;
  34. cin>>n;
  35. findconsecutive(n);
  36. return 0;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement