Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long t; // number of test cases
- cin >> t;
- while (t-- > 0)
- {
- long long x; // number
- long long a = -1; // a + a+1 + a+2 +.....+ a+n = x
- long long s1 = 1; // 1+2+3+...+n
- long long s2 = 0; // 1+1+1+2+...+1+n (a==1 wcs)
- long long sh = 2; // help at calculating s1
- cin >> x;
- for (long long i = 2; s2 <= x; i++) // looking for < a >
- {
- if ((x - s1) % i == 0)
- {
- cout << "x=" << x << " " // value of x
- << "s1=" << s1 << " " // value of s1
- << "i=" << i << '\n'; // value of i
- a = (x - s1) % i == 0;
- cout << a << '\n';
- break;
- }
- s2 += 1 + s1;
- s1 += sh;
- sh += 1;
- }
- cout << a << endl;
- if (a == -1)
- {
- cout << "IMPOSSIBLE" << '\n';
- continue;
- }
- cout << a << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment