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, z2; // number
- long long a = -1; // a + a+1 + a+2 +.....+ a+n = x
- long long s1 = 1; // 1+2+3+...+n
- long long sh = 2; // help at calculating s1
- cin >> x;
- for (long long i = 2; s1 <= x; i++) // looking for < a >
- {
- s1 += i;
- if ((x - s1) % i == 0)
- {
- z2 = i;
- a = (x - s1) / i;
- break;
- }
- }
- if (a == -1)
- {
- cout << "IMPOSSIBLE" << '\n';
- }
- else
- {
- a += 1;
- cout << x << " "
- << "="
- << " ";
- for (int i = 1; i < z2; i++)
- {
- cout << a << " "
- << "+"
- << " ";
- a += 1;
- }
- cout << a << '\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment