#include #include #include #include #include #include #include #include #include #include #include #include #include #define getchar getchar_unlocked #define putchar putchar_unlocked #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i64 = long long; using u8 = unsigned char; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; int get_int() { int c, n; while ((c = getchar()) < '0'); n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + (c - '0'); return n; } f80 fractional_part(int N) { f80 v = sqrtl(N); int iv = v; i64 numer = N - iv * iv; return numer / (v + iv); } void solve() { const int base = 1234567; const int K = 2400; vector ns(K); rep(i, K) ns[i] = rand() % base; vector< pair > values; vector fs; rep(i, K) fs.push_back(fractional_part(ns[i])); rep(i, K) rep(j, i, K) { f80 a = fs[i] + fs[j]; if (a >= 1) a -= 1; values.emplace_back(a, i + j * K); } sort(values.begin(), values.end()); int Q; scanf("%d", &Q); rep(i, Q) { f80 f; scanf("%Lf", &f); f80 target = f - (i64) f;; int tail = lower_bound( values.begin(), values.end(), make_pair(target, 100000000)) - values.begin(); if (tail == (int) values.size()) --tail; int head = 0; f80 best = 1e-6; i64 mask = 0; while (head < (int) values.size() && tail >= 0) { f80 s = values[head].first + values[tail].first; if (s < target) { if (target - s < best) { best = target - s; mask = values[head].second + i64(values[tail].second) * K * K; } head++; } else { if (s - target < best) { best = s - target; mask = values[head].second + i64(values[tail].second) * K * K; } --tail; } if (best < 1e-10) break; } // fprintf(stderr, "%.16Lf\n", best); // fprintf(stderr, "%.16Lf\n", t); // fprintf(stderr, "%.16Lf\n", f); assert(best < 1e-10); f80 t = 0; printf("%d", 5); rep(_, 4) { int j = mask % K; mask /= K; t += sqrtl(ns[j]); printf(" %d", ns[j]); } int integer_part = (int) round(f - t); t += integer_part; assert(integer_part >= 0); printf(" %d\n", integer_part * integer_part); assert((f - t) < 1e-9); } } int main() { clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); return 0; }