#include #include #include #include #include #include typedef unsigned long long int ulli; ulli fact(int n, std::vector& factCache) { ulli lastFact = factCache[factCache.size() - 1]; if (factCache.size() > n) { return factCache[n]; } for (int i = factCache.size(); i <= n; ++i) { factCache.push_back(lastFact * i); lastFact *= i; } return factCache[n]; } ulli binomial(int n, int k, std::vector& factCache) { return (fact(n, factCache)) / ((fact(k, factCache)) * (fact((n-k), factCache))); } int solve(std::vector& cache) { int input; std::cin >> input; if (input == 1) return 1; using binomialNum = std::pair; std::priority_queue q; std::set map; q.push(std::make_pair(2, 1)); map.insert(std::make_pair(2, 3)); while (!q.empty()) { binomialNum current = q.top(); map.insert(current); binomialNum nextA = std::make_pair(current.first + 1, current.second); binomialNum nextB = std::make_pair(current.first + 1, current.second + 1); ulli aVal = binomial(nextA.first, nextA.second, cache); ulli bVal = binomial(nextB.first, nextB.second, cache); if (aVal == input || bVal == input) return nextA.first + 1; bool containsA = map.find(nextA) != map.end(); bool containsB = map.find(nextB) != map.end(); q.pop(); if (aVal == bVal) { if (aVal < input && !containsA) { q.push(nextA); } } else { if (aVal < input && !containsA) { q.push(nextA); } if (bVal < input && !containsB) { q.push(nextB); } } } return -1; } int main() { std::vector factCache; factCache.push_back(1); factCache.push_back(1); int input; std::cin >> input; for (int i = 0; i < input; ++i) { std::cout << solve(factCache) << std::endl; } return 0; }