T3000

Untitled

Jan 13th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     long long t; // number of test cases
  8.     cin >> t;
  9.     while (t-- > 0)
  10.     {
  11.         long long x;      // number
  12.         long long a = -1; // a + a+1 + a+2 +.....+ a+n = x
  13.         long long s1 = 1; // 1+2+3+...+n
  14.         long long s2 = 0; // 1+1+1+2+...+1+n (a==1 wcs)
  15.         long long sh = 2; // help at calculating s1
  16.         cin >> x;
  17.         for (long long i = 2; s2 <= x; i++) // looking for < a >
  18.         {
  19.             if ((x - s1) % i == 0)
  20.             {
  21.                 cout << "x=" << x << " "   // value of x
  22.                      << "s1=" << s1 << " " // value of s1
  23.                      << "i=" << i << '\n'; // value of i
  24.                 a = (x - s1) % i == 0;
  25.                 cout << a << '\n';
  26.                 break;
  27.             }
  28.             s2 += 1 + s1;
  29.  
  30.             s1 += sh;
  31.             sh += 1;
  32.         }
  33.         cout << a << endl;
  34.         if (a == -1)
  35.         {
  36.             cout << "IMPOSSIBLE" << '\n';
  37.             continue;
  38.         }
  39.         cout << a << endl;
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment