Advertisement
Saleh127

Live ar 6929

May 22nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12.  
  13.  
  14. ll n,m,j,i,k,l,Sn,a;
  15.  
  16. cin>>n;
  17.  
  18. if(n<=2)
  19. {
  20. cout<<"IMPOSSIBLE"<<endl;
  21. continue;
  22. }
  23.  
  24. if(n%2)
  25. {
  26. cout<<n<<" = "<<n/2<<" + "<<1+n/2<<endl;
  27. continue;
  28. }
  29.  
  30. m=n;
  31.  
  32. while(m%2==0) m/=2;
  33.  
  34. if(m==1)
  35. {
  36. cout<<"IMPOSSIBLE"<<endl;
  37. continue;
  38. }
  39.  
  40. for(i=3;;i++)
  41. {
  42. /// a= first element
  43.  
  44. /// Sn= n/2 * {2a+n(n-1)d};
  45.  
  46. /// a={Sn-(n(n-1)*d/2}/n;
  47.  
  48. a=(n-(i*(i-1))/2)/i;
  49.  
  50. Sn=(a*i+(i*(i-1))/2);
  51.  
  52. if(Sn==n)
  53. {
  54. break;
  55. }
  56. }
  57.  
  58. cout<<n<<" = "<<a;
  59.  
  60. for(j=0;j<i-1;j++)
  61. {
  62. cout<<" + "<<++a;
  63. }
  64. cout<<endl;
  65. }
  66.  
  67. return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement