天天看点

Luogu P4759 [CERC2014]Sums

题目链接:​​传送门​​

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <ctime>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
int T, n, ans[A];

int main(int argc, char *argv[]) {
//  freopen("xx.out", "w", stdout);
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    int ok = 0, cnt = 0;
    for (int x = 2; x <= sqrt(2 * n); x++)
      if ((n - ((x + 1) * x) / 2) % x == 0) {
        int xx = ((n - ((x + 1) * x) / 2) / x), sum = 0;
        while (sum < n) ans[++cnt] = ++xx, sum += xx;
        ok = 1; break;
      }
    if (!ok) puts("IMPOSSIBLE");
    else {
      printf("%d =", n);
      for (int i = 1; i <= cnt; i++)
        if (i == cnt) printf(" %d", ans[i]);
        else printf(" %d +", ans[i]);
      puts("");
    }
  }
  return 0;
}