1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <set> #include <vector> using namespace std;
const int INF = ~0u>>1; typedef pair <int,int> P; #define MID(x,y) ((x+y)>>1) #define iabs(x) ((x)>0?(x):-(x)) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define mp make_pair #define print() cout<<"--------"<<endl
int check(int n){ int k = max(0,(int)sqrt(2 * n) - 4); for (int i = k; i * i <= 2 * n; i ++){ if (i * i + i == 2 * n) return i; } return 0; }
int main(){ int T,n; cin >> T; while (T--){ scanf("%d", &n); int l,k = check(n); if (k){ printf("%dn", k); }else { bool flag = 0; for (int i = 1; i * i + i <= 2 * n; i ++){ l = check(n - (i + 1) * i /2); if (l){ printf("%d %dn", i, l); flag = 1; break; } } if (!flag){ for (int i = 1; i * i + i <= 2 * n && !flag; i ++){ int mod = n - (i + 1) * i / 2; for (int j = 1; j * (j + 1) / 2 <= mod && !flag; j ++){ l = check(n - (j*(j+1)/2) - i * (i + 1) /2); if (l){ printf("%d %d %dn", i, j ,l); flag = 1; break; } } } } } } return 0; }
|