Problem:
Problem E:
Subdividing a Land
Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square,
all of whose edges are equally
a
meters. The complex contains
n
subdivided blocks, each of which is a
b
-meter
square. Here both
a
and
b
are positive integers.
However the project is facing a big problem. In this country, a percentage limit applies to the subdivision of a
land, under the pretext of environmental protection. When developing a complex, the total area of the subdivided
blocks must not exceed 50% of the area of the complex; in other words, more than or equal to 50% of the newly
developed housing complex must be kept for green space. As a business, a green space exceeding 50% of the
total area is a
dead space
. The primary concern of the project is to minimize it.
Of course purchasing and developing a land costs in proportion to its area, so the company also wants to minimize
the land area to develop as the secondary concern. You, a member of the project, were assigned this task, but can
no longer stand struggling against the problem with your pencil and paper. So you decided to write a program to
find the pair of minimum
a
and
b
among those which produce the minimum dead space for given
n
.
Input
The input consists of multiple test cases. Each test case comes in a line, which contains an integer
n
. You may
assume 1 ≤
n
≤ 10000.
The end of input is indicated by a line containing a single zero. This line is not a part of the input and should not
be processed.
Output
For each test case, output the case number starting from 1 and the pair of minimum
a
and
b
as in the sample
output.
You may assume both
a
and
b
fit into 64-bit signed integers.
Sample Input
1
2
0
Output for the Sample Input
Case 1: 3 2
Case 2: 2 1

Submitted solutions:

code_snippet: #ifndef HIDDEN_IN_VS // 折りたたみ用

// 警告の抑制
#define _CRT_SECURE_NO_WARNINGS

// ライブラリの読み込み
#include <bits/stdc++.h>
using namespace std;

// 型名の短縮
using ll = long long; // -2^63 ～ 2^63 = 9 * 10^18（int は -2^31 ～ 2^31 = 2 * 10^9）
using pii = pair<int, int>;	using pll = pair<ll, ll>;	using pil = pair<int, ll>;	using pli = pair<ll, int>;
using vi = vector<int>;		using vvi = vector<vi>;		using vvvi = vector<vvi>;
using vl = vector<ll>;		using vvl = vector<vl>;		using vvvl = vector<vvl>;
using vb = vector<bool>;	using vvb = vector<vb>;		using vvvb = vector<vvb>;
using vc = vector<char>;	using vvc = vector<vc>;		using vvvc = vector<vvc>;
using vd = vector<double>;	using vvd = vector<vd>;		using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;

// 定数の定義
const double PI = acos(-1);
const vi DX = { 1, 0, -1, 0 }; // 4 近傍（下，右，上，左）
const vi DY = { 0, 1, 0, -1 };
int INF = 1001001001; ll INFL = 4004004004004004004LL;
double EPS = 1e-12;

// 入出力高速化
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;

// 汎用マクロの定義
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順
#define repe(v, a) for(const auto& v : (a)) // a の全要素（変更不可能）
#define repea(v, a) for(auto& v : (a)) // a の全要素（変更可能）
#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d ビット全探索（昇順）
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て（昇順）
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去
#define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了

// 汎用関数の定義
template <class T> inline ll pow(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新（更新されたら true を返す）
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新（更新されたら true を返す）

// 演算子オーバーロード
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }

// 手元環境（Visual Studio）
#ifdef _MSC_VER
#include "local.hpp"
// 提出用（gcc）
#else
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
#define gcd __gcd
#define dump(...)
#define dumpel(v)
#define dump_list(v)
#define dump_list2D(v)
#define input_from_file(f)
#define output_to_file(f)
#define Assert(b) { if (!(b)) while (1) cout << "OLE"; }
#endif

#endif // 折りたたみ用


////--------------AtCoder 専用--------------
//#include <atcoder/all>
//using namespace atcoder;
//
//using mint = modint1000000007;
////using mint = modint998244353;
////using mint = modint; // mint::set_mod(m);
//
//istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
//ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
//using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;
////----------------------------------------


void oeis_to_umekomi() {
	// 元データ：
	// http://oeis.org/A002350
	// http://oeis.org/A002349

	int n = 10000;

	vl x(n + 1, -1), y(n + 1, -1);

	repi(i, 1, n) {
		int id; string xs;
		cin >> id >> xs;

		if (id % 2 == 1) continue;

		try {
			x[i] = stoll(xs);
		}
		catch (const out_of_range&) {
			continue;
		}
	}

	repi(i, 1, n) {
		int id; string ys;
		cin >> id >> ys;

		if (id % 2 == 1) continue;

		try {
			y[i] = stoll(ys);
		}
		catch (const out_of_range&) {
			continue;
		}
	}

	// AOJ のソースコードサイズ上限の 30KB に収まってくれなかった．
	x.resize(1000); cout << "vl X = "; dump_list(x); cout << ";\n";
	y.resize(1000); cout << "vl Y = "; dump_list(y); cout << ";\n";

	exit(0);
}

vl X = { -1, -1, 3, -1, 1, -1, 5, -1, 3, -1, 19, -1, 7, -1, 15, -1, 1, -1, 17, -1, 9, -1, 197, -1, 5, -1, 51, -1, 127, -1, 11, -1, 17, -1, 35, -1, 1, -1, 37, -1, 19, -1, 13, -1, 199, -1, 24335, -1, 7, -1, 99, -1, 649, -1, 485, -1, 15, -1, 19603, -1, 31, -1, 63, -1, 1, -1, 65, -1, 33, -1, 251, -1, 17, -1, 3699, -1, 57799, -1, 53, -1, 9, -1, 163, -1, 55, -1, 10405, -1, 197, -1, 19, -1, 1151, -1, 2143295, -1, 49, -1, 99, -1, 1, -1, 101, -1, 51, -1, 32080051, -1, 1351, -1, 21, -1, 127, -1, 1025, -1, 9801, -1, 306917, -1, 11, -1, 243, -1, 4620799, -1, 449, -1, 577, -1, 6499, -1, 23, -1, 145925, -1, 35, -1, 47, -1, 71, -1, 143, -1, 1, -1, 145, -1, 73, -1, 49, -1, 37, -1, 21295, -1, 25, -1, 7743, -1, 721, -1, 19601, -1, 2049, -1, 1700902565, -1, 13, -1, 339, -1, 24248647, -1, 1451, -1, 199, -1, 1601, -1, 161, -1, 27, -1, 24335, -1, 7501, -1, 4607, -1, 52021, -1, 97, -1, 195, -1, 1, -1, 197, -1, 99, -1, 19731763, -1, 4999, -1, 59535, -1, 649, -1, 29, -1, 66249, -1, 695359189925, -1, 485, -1, 126003, -1, 89, -1, 149, -1, 15, -1, 451, -1, 151, -1, 91, -1, 19603, -1, 5201, -1, 561799, -1, 11663, -1, 31, -1, 19601, -1, 1766319049, -1, 88805, -1, 63, -1, 39480499, -1, 127, -1, 255, -1, 1, -1, 257, -1, 129, -1, 104980517, -1, 65, -1, 685, -1, 4771081927, -1, 5291, -1, 33, -1, 3959299, -1, 7775, -1, 2501, -1, 251, -1, 2351, -1, 24220799, -1, 561835, -1, 17, -1, 579, -1, 2281249, -1, 4801, -1, 3699, -1, 335473872499, -1, 1351, -1, 4276623, -1, 57799, -1, 35, -1, 351, -1, 848719, -1, 53, -1, 392499, -1, 12799, -1, 107, -1, 161, -1, 323, -1, 1, -1, 325, -1, 163, -1, 109, -1, 13447, -1, 63804373719695, -1, 55, -1, 114243, -1, 285769, -1, 37, -1, 10405, -1, 17299, -1, 1567, -1, 449, -1, 77617, -1, 258065, -1, 500001, -1, 176579805797, -1, 19, -1, 723, -1, 4954951, -1, 907925, -1, 1151, -1, 213859, -1, 12151, -1, 3365, -1, 2143295, -1, 8749, -1, 39, -1, 164998439999, -1, 4801, -1, 111555, -1, 62809633, -1, 79, -1, 99, -1, 312086396361222451, -1, 199, -1, 399, -1, 1, -1, 401, -1, 201, -1, 59468095, -1, 101, -1, 81, -1, 103537981567, -1, 24335, -1, 5201, -1, 33857, -1, 41, -1, 7022501, -1, 32080051, -1, 88751, -1, 1850887, -1, 2862251, -1, 1351, -1, 125, -1, 158070671986249, -1, 293, -1, 21, -1, 883, -1, 295, -1, 110166015, -1, 127, -1, 19601, -1, 1204353, -1, 16916040084175685, -1, 1025, -1, 22899, -1, 2535751, -1, 43, -1, 9801, -1, 938319425, -1, 649, -1, 1691, -1, 306917, -1, 193549, -1, 28799, -1, 1617319577991743, -1, 241, -1, 483, -1, 1, -1, 485, -1, 243, -1, 1039681, -1, 29767, -1, 73035, -1, 4620799, -1, 179777, -1, 930249, -1, 3832352837, -1, 449, -1, 45, -1, 44757606858751, -1, 271, -1, 665857, -1, 4625, -1, 16855, -1, 2367, -1, 6499, -1, 19603, -1, 225144199, -1, -1, -1, 23, -1, 1059, -1, 2588599, -1, 3678725, -1, 145925, -1, 9536081203, -1, 119071, -1, 4293183, -1, 2449, -1, 701, -1, 6083073, -1, 30580901, -1, 47, -1, 60756099699, -1, 12032115501124999, -1, 7937, -1, 71, -1, 220938497, -1, 95, -1, 95609285, -1, 143, -1, 191, -1, 287, -1, 575, -1, 1, -1, 577, -1, 289, -1, 193, -1, 145, -1, -1, -1, 97, -1, 5781, -1, 73, -1, 1098305, -1, 25801741449, -1, 1574351, -1, 49, -1, 687, -1, 5972991296311683199, -1, 42187499, -1, 2737, -1, 10323982819, -1, 2177, -1, 348291186245, -1, 21295, -1, 10093, -1, 249, -1, 13804370063, -1, 25, -1, 1251, -1, 46698728731849, -1, 251, -1, 7743, -1, -1, -1, 3505951, -1, 42283, -1, 1039681, -1, 5777, -1, 11775, -1, 305, -1, 19601, -1, 51, -1, 8212499464321351, -1, 8915765, -1, 2049, -1, 1693, -1, 1079, -1, 1718102501, -1, 1700902565, -1, 27365201, -1, 56447, -1, 5791211, -1, 337, -1, 675, -1, 1, -1, 677, -1, 339, -1, 1197901, -1, 57799, -1, 10850138895, -1, 24248647, -1, 1471, -1, 2499849, -1, -1, -1, 1451, -1, 51999603, -1, 8193151, -1, 53, -1, 79201, -1, 34595, -1, 62423, -1, 1279, -1, 1601, -1, 4115, -1, 35115719688199, -1, 8933399183036079503, -1, 161, -1, 22619537, -1, 2469645423824185801, -1, 485, -1, 27, -1, 1459, -1, 487, -1, 10394175, -1, 24335, -1, 163, -1, 9249, -1, 263091151, -1, 7501, -1, 61268974069299, -1, 5658247, -1, 2550251, -1, 4607, -1, 836977699, -1, 55, -1, 413959717, -1, 52021, -1, 6349, -1, 161784071999999, -1, -1, -1, 18817, -1, 111, -1, 6224323426849, -1, 10405, -1, 195, -1, 5964562960504723, -1, 391, -1, 783, -1, 1, -1, 785, -1, 393, -1, 6616066879, -1, 197, -1, 1828310451, -1, -1, -1, 113, -1, 19601, -1, 295496099, -1, 515095, -1, 6166395, -1, 19731763, -1, 27379, -1, 57, -1, 4206992174549, -1, 4999, -1, 40899, -1, 39689, -1, 7397, -1, 59535, -1, 222239304685, -1, 1151, -1, 146411, -1, 842401, -1, 6552578705, -1, 46551, -1, 42112785797, -1, 29, -1, 1683, -1, -1, -1, 2143295, -1, 66249, -1, 2449, -1, 194399, -1, 1294299, -1, 695359189925, -1, 703, -1, 3871, -1, -1, -1, 470449, -1, 42435, -1, 3844063, -1, 59, -1, 126003, -1, 3725, -1, 10951, -1, 9314703, -1, 89, -1, 19601, -1, 1665, -1, -1, -1, 149, -1, 179, -1, 100351, -1, 299, -1, 449, -1, 899, -1, 1, -1, 901, -1, 451, -1, 301, -1, 102151, -1, 181, -1, 151, -1, 62563299, -1, 5848201, -1, 4120901, -1, 91, -1, 351605368773852499, -1, 11551, -1, 304560297142335, -1, 768555217, -1, 61, -1, 1072400673, -1, 3034565, -1, 5201, -1, 17151, -1, 4231, -1, 106133, -1, 561799, -1, 45225786400145, -1, 228151, -1, 202501, -1, 11663, -1, 32080051, -1, 76759023628799, -1, 16762522330425599, -1, 31, -1, 1923, -1, 10085143557001249, -1, 57499, -1, 19601, -1, 215395035859, -1, 9863382151, -1, 488825745235215, -1, 1766319049, -1, 118337, -1, 51841, -1, 8837, -1, 88805, -1, 49299, -1, 14549450527, -1, 881, -1, 63, -1, 1135, -1, 8553815, -1, 984076901, -1 };
vl Y = { -1, -1, 2, -1, 0, -1, 2, -1, 1, -1, 6, -1, 2, -1, 4, -1, 0, -1, 4, -1, 2, -1, 42, -1, 1, -1, 10, -1, 24, -1, 2, -1, 3, -1, 6, -1, 0, -1, 6, -1, 3, -1, 2, -1, 30, -1, 3588, -1, 1, -1, 14, -1, 90, -1, 66, -1, 2, -1, 2574, -1, 4, -1, 8, -1, 0, -1, 8, -1, 4, -1, 30, -1, 2, -1, 430, -1, 6630, -1, 6, -1, 1, -1, 18, -1, 6, -1, 1122, -1, 21, -1, 2, -1, 120, -1, 221064, -1, 5, -1, 10, -1, 0, -1, 10, -1, 5, -1, 3115890, -1, 130, -1, 2, -1, 12, -1, 96, -1, 910, -1, 28254, -1, 1, -1, 22, -1, 414960, -1, 40, -1, 51, -1, 570, -1, 2, -1, 12606, -1, 3, -1, 4, -1, 6, -1, 12, -1, 0, -1, 12, -1, 6, -1, 4, -1, 3, -1, 1716, -1, 2, -1, 616, -1, 57, -1, 1540, -1, 160, -1, 132015642, -1, 1, -1, 26, -1, 1848942, -1, 110, -1, 15, -1, 120, -1, 12, -1, 2, -1, 1794, -1, 550, -1, 336, -1, 3774, -1, 7, -1, 14, -1, 0, -1, 14, -1, 7, -1, 1388322, -1, 350, -1, 4148, -1, 45, -1, 2, -1, 4550, -1, 47533775646, -1, 33, -1, 8534, -1, 6, -1, 10, -1, 1, -1, 30, -1, 10, -1, 6, -1, 1287, -1, 340, -1, 36570, -1, 756, -1, 2, -1, 1260, -1, 113076990, -1, 5662, -1, 4, -1, 2496966, -1, 8, -1, 16, -1, 0, -1, 16, -1, 8, -1, 6485718, -1, 4, -1, 42, -1, 291440214, -1, 322, -1, 2, -1, 239190, -1, 468, -1, 150, -1, 15, -1, 140, -1, 1437240, -1, 33222, -1, 1, -1, 34, -1, 133500, -1, 280, -1, 215, -1, 19433479650, -1, 78, -1, 246092, -1, 3315, -1, 2, -1, 20, -1, 48204, -1, 3, -1, 22150, -1, 720, -1, 6, -1, 9, -1, 18, -1, 0, -1, 18, -1, 9, -1, 6, -1, 738, -1, 3491219999244, -1, 3, -1, 6214, -1, 15498, -1, 2, -1, 561, -1, 930, -1, 84, -1, 24, -1, 4137, -1, 13716, -1, 26500, -1, 9332532726, -1, 1, -1, 38, -1, 259710, -1, 47458, -1, 60, -1, 11118, -1, 630, -1, 174, -1, 110532, -1, 450, -1, 2, -1, 8442054600, -1, 245, -1, 5678, -1, 3188676, -1, 4, -1, 5, -1, 15722685507826110, -1, 10, -1, 20, -1, 0, -1, 20, -1, 10, -1, 2951352, -1, 5, -1, 4, -1, 5100950232, -1, 1196, -1, 255, -1, 1656, -1, 2, -1, 341850, -1, 1557945, -1, 4300, -1, 89466, -1, 138030, -1, 65, -1, 6, -1, 7570212227550, -1, 14, -1, 1, -1, 42, -1, 14, -1, 5216512, -1, 6, -1, 924, -1, 56648, -1, 793909098494766, -1, 48, -1, 1070, -1, 118230, -1, 2, -1, 455, -1, 43466808, -1, 30, -1, 78, -1, 14127, -1, 8890, -1, 1320, -1, 73974475657896, -1, 11, -1, 22, -1, 0, -1, 22, -1, 11, -1, 46968, -1, 1342, -1, 3286, -1, 207480, -1, 8056, -1, 41602, -1, 171046278, -1, 20, -1, 2, -1, 1985797689600, -1, 12, -1, 29427, -1, 204, -1, 742, -1, 104, -1, 285, -1, 858, -1, 9835470, -1, 3665019757324295532, -1, 1, -1, 46, -1, 112230, -1, 159194, -1, 6303, -1, 411129654, -1, 5124, -1, 184408, -1, 105, -1, 30, -1, 259856, -1, 1303974, -1, 2, -1, 2581279330, -1, 510275358434250, -1, 336, -1, 3, -1, 9319728, -1, 4, -1, 4018758, -1, 6, -1, 8, -1, 12, -1, 24, -1, 0, -1, 24, -1, 12, -1, 8, -1, 6, -1, 1399069112058008310, -1, 4, -1, 238, -1, 3, -1, 45064, -1, 1056880510, -1, 64380, -1, 2, -1, 28, -1, 243037569063951720, -1, 1713750, -1, 111, -1, 418005846, -1, 88, -1, 14055888354, -1, 858, -1, 406, -1, 10, -1, 553504812, -1, 1, -1, 50, -1, 1863482146110, -1, 10, -1, 308, -1, -1, -1, 139020, -1, 1674, -1, 41097, -1, 228, -1, 464, -1, 12, -1, 770, -1, 2, -1, 321626301297510, -1, 348634, -1, 80, -1, 66, -1, 42, -1, 66775950, -1, 66007821, -1, 1060380, -1, 2184, -1, 223734, -1, 13, -1, 26, -1, 0, -1, 26, -1, 13, -1, 45870, -1, 2210, -1, 414260228, -1, 924471, -1, 56, -1, 95030, -1, -1, -1, 55, -1, 1968214, -1, 309672, -1, 2, -1, 2985, -1, 1302, -1, 2346, -1, 48, -1, 60, -1, 154, -1, 1312336060110, -1, 333391496474140716, -1, 6, -1, 841812, -1, 91783649341730970, -1, 18, -1, 1, -1, 54, -1, 18, -1, 383656, -1, 897, -1, 6, -1, 340, -1, 9658380, -1, 275, -1, 2243216519470, -1, 206886, -1, 93122, -1, 168, -1, 30480930, -1, 2, -1, 15035694, -1, 1887, -1, 230, -1, 5853142302000, -1, 5272795728865625208, -1, 679, -1, 4, -1, 224018302020, -1, 374, -1, 7, -1, 213839942395674, -1, 14, -1, 28, -1, 0, -1, 28, -1, 14, -1, 235389096, -1, 7, -1, 64884310, -1, -1, -1, 4, -1, 693, -1, 10434330, -1, 18166, -1, 217202, -1, 694161, -1, 962, -1, 2, -1, 147454999410, -1, 175, -1, 1430, -1, 1386, -1, 258, -1, 2074, -1, 7732694382, -1, 40, -1, 5082, -1, 29205, -1, 226897244, -1, 1610, -1, 1454762046, -1, 1, -1, 58, -1, -1, -1, 73688, -1, 2275, -1, 84, -1, 6660, -1, 44290, -1, 23766887823, -1, 24, -1, 132, -1, -1, -1, 16005, -1, 1442, -1, 130476, -1, 2, -1, 4267, -1, 126, -1, 370, -1, 314356, -1, 3, -1, 660, -1, 56, -1, -1, -1, 5, -1, 6, -1, 3360, -1, 10, -1, 15, -1, 30, -1, 0, -1, 30, -1, 15, -1, 10, -1, 3390, -1, 6, -1, 5, -1, 2069410, -1, 193230, -1, 136010, -1, 3, -1, 11579506138834350, -1, 380, -1, 10008472361032, -1, 25229061, -1, 2, -1, 35127652, -1, 99294, -1, 170, -1, 560, -1, 138, -1, 3458, -1, 18285, -1, 1470417148788, -1, 7410, -1, 6570, -1, 378, -1, 1038630, -1, 2482564242480, -1, 541572514048560, -1, 1, -1, 62, -1, 324820602522300, -1, 1850, -1, 630, -1, 6915917802, -1, 316368130, -1, 15662987185124, -1, 56538495, -1, 3784, -1, 1656, -1, 282, -1, 2831, -1, 1570, -1, 462879684, -1, 28, -1, 2, -1, 36, -1, 271038, -1, 31150410, -1 };


// 答えがそんなに大きくならないなら long double の計算でいけんじゃね？と思ったけど余裕で無理だった．
pll solve_WA(int n) {
	n *= 2;

	using ld = long double;
	ld x = sqrt(ld(n));

	EPS = 1e-5;
	if (abs(x - round(x)) < EPS) return { (ll)(x + 0.1), 1LL };

	using vld = vector<ld>;
	vld seen;

	vl a;

	while (true) {
		dump(x);
		a.push_back((ll)floor(x));
		x = 1 / (x - a.back());

		bool end_flag = false;
		repe(y, seen) if (abs(y - x) < EPS) { end_flag = true; break; };
		if (end_flag) break;

		seen.push_back(x);
	}
	dump(seen); dump(a);

	int m = sz(a);
	ll num = a[m - 2], dnm = 1;
	repir(i, m - 3, 0) { swap(num, dnm); num += dnm * a[i]; };
	dump(num, dnm);

	if (m % 2 == 0) {
		ll tmp = 2 * num * dnm;
		num = num * num + n * dnm * dnm;
		dnm = tmp;
	}
	dump(num, dnm);

	return { num, dnm };
}


pll solve(int n) {
	n *= 2;

	using ld = long double;
	ld sqrt_n = sqrt(ld(n));
	ll a = 0, b = 1, c = 1; // (a + b√n) / c

	EPS = 1e-5;
	if (abs(sqrt_n - round(sqrt_n)) < EPS) return { (ll)(sqrt_n + 0.1), 1LL };

	set<tuple<ll, ll, ll>> seen; vl seq;

	while (true) {
		dump(a, b, c);

		ld x = (a + b * sqrt_n) / c;
		ll k = (ll)floor(x);
		seq.push_back(k);

		ll na = c * (a - k * c);
		ll nb = -b * c;
		ll nc = (a - k * c) * (a - k * c) - n * b * b;
		ll g = gcd(gcd(abs(na), abs(nb)), abs(nc));
		if (nc < 0) g *= -1;
		a = na / g; b = nb / g; c = nc / g;
		
		if (seen.count({ a, b, c })) break;

		seen.insert({ a, b, c });
	}
	dump(seen); dump(a);

	int m = sz(seq);
	ll num = seq[m - 2], dnm = 1;
	repir(i, m - 3, 0) { swap(num, dnm); num += dnm * seq[i]; };
	dump(num, dnm);

	if (m % 2 == 0) {
		ll tmp = 2 * num * dnm;
		num = num * num + n * dnm * dnm;
		dnm = tmp;
	}
	dump(num, dnm);

	return { num, dnm };
}


void find_bug() {
#ifdef _MSC_VER
	// 合わない入力例を見つける．

	mt19937_64 mt;
	mt.seed((int)time(NULL));
	uniform_int_distribution<ll> rnd(0LL, 1LL << 62);

	mute_dump = true;

	repi(n, 1, 1000) {
		if (X[2 * n] == -1 || Y[2 * n] == -1 || Y[2 * n] == 0) continue;
		cout << n << endl;

		pll res_naive = { X[2 * n], Y[2 * n] };
		auto res_solve = solve(n);

		if (res_naive != res_solve) {
			cout << "----------error!----------" << endl;
			cout << "input:" << endl;
			cout << n << endl;
			cout << "results:" << endl;
			cout << res_naive << endl;
			cout << res_solve << endl;
			cout << "--------------------------" << endl;
		}
	}

	mute_dump = false;
	exit(0);
#endif
}


int main() {
//	input_from_file("input.txt");
//	output_to_file("output.txt");

//	oeis_to_umekomi();
//	find_bug();

	rep(hoge, 1234567) {
		int n;
		cin >> n;

		if (n == 0) return 0;

		ll a, b;
		tie(a, b) = solve(n);

		cout << "Case " << hoge + 1 << ": " << a << " " << b << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3252
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef pair<lint,lint>pll;

// 連分数を使って、基本単数を求める。d は平方数でないことが要請される。
pll fundamental_unit(lint d){
  vector<int> ans;
  lint x=0,z=1;//(x+sqrt(d))/z
  lint sqrtd=floor(sqrt(d));
  set<pll>seen;
  // invariants: x>=0, z|x*x-d
  while(1){
    if(seen.count(pll(x,z)))break;
    seen.insert(pll(x,z));
    lint q=(x+sqrtd)/z;
    ans.push_back(q);
    x=q*z-x;
    lint norm=x*x-d;
    z=-norm/z;
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  for(int i=0;i<=200;++i)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3136
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<lint,lint>pll;

// 連分数を使って、基本単数を求める。d は平方数でないことが要請される。
pll fundamental_unit(lint d){
  vi ans;
  lint x=0,z=1;//(x+sqrt(d))/z
  lint sqrtd=floor(sqrt(d));
  set<pll>seen;
  // invariants: x>=0, z|x*x-d
  while(1){
    if(seen.count(pll(x,z)))break;
    seen.insert(pll(x,z));
    lint q=(x+sqrtd)/z;
    ans.push_back(q);
    x=q*z-x;
    lint norm=x*x-d;
    z=-norm/z;
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  for(int i=0;i<=200;++i)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3076
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<lint,lint>pll;
typedef pair<pll,lint>pplll;

pll fundamental_unit(lint d){
  vi ans;
  lint x=0,z=1;//(x+y*sqrt(d))/z
  lint sqrtd=floor(sqrt(d));
  set<pll>seen;
  while(1){
    if(seen.count(pll(x,z)))break;
    seen.insert(pll(x,z));
    lint q=((x+sqrtd)/z);
    if(0){
      cerr<<"x,z=("<<x<<"+sqrt(d))/"<<z<<endl;
      cerr<<"q="<<q<<endl;
    }
    ans.push_back(q);
    x-=q*z;
    lint norm=x*x-d;
    x=-x;
    z=-norm/z;
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  for(int i=0;i<=200;++i)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3156
final_rank: 5

code_snippet: #include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef pair<lint,lint>pll;
typedef pair<pll,lint>pplll;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

pll fundamental_unit(lint d){
  vi ans;
  lint x=0,y=1,z=1;//(x+y*sqrt(d))/z
  double sqrtd=sqrt(d);
  set<pplll>seen;
  while(1){
    if(seen.count(pplll(pll(x,y),z)))break;
    seen.insert(pplll(pll(x,y),z));
    lint q=floor((x+sqrtd*y)/z);
    if(0){
      cerr<<"x,y,z=("<<x<<"+"<<y<<"*sqrt(d))/"<<z<<endl;
      cerr<<"q="<<q<<endl;
    }
    ans.push_back(q);
    x-=q*z;
    lint norm=x*x-d*y*y;
    y=-y;
    z=norm/z;
    if(z<0){
      x=-x;y=-y;z=-z;
    }
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  rep(i,200)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3116
final_rank: 3

code_snippet: #include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[100];
long long s[100];
long long t[100];
long long x[100];
long long y[100];
int main(){
	int T=0;
	int n;
	while(scanf("%d",&n),n){
		n*=2;
		int p=(int)(sqrt((double)n+0.00000005));
		if(p*p==n){
			printf("Case %d: %d %d\n",++T,p,1);
			continue;
		}
		long double now=sqrt((long double)n);
		a[0]=(long long)now;
		s[0]=0;t[0]=1;
		x[0]=1;y[0]=0;
		x[1]=a[0];y[1]=1;
		for(int i=0;i<50;i++){
			s[i+1]=a[i]*t[i]-s[i];
			t[i+1]=((long long)n-s[i+1]*s[i+1])/t[i];
			a[i+1]=(a[0]+s[i+1])/t[i+1];
			x[i+2]=a[i+1]*x[i+1]+x[i];
			y[i+2]=a[i+1]*y[i+1]+y[i];
	//		printf("%lld %lld %lld %lld %lld\n",s[i+1],t[i+1],a[i+1],x[i+2],y[i+2]);
			if(t[i+1]==1&&x[i+1]*x[i+1]-y[i+1]*y[i+1]*n==1){
				printf("Case %d: %lld %lld\n",++T,x[i+1],y[i+1]);
				break;
			}
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1032
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;
#define EQ(a,b) (abs(a-b)<EPS)
typedef pair<ll,ll> pll;
typedef complex<double> Complex;

struct Long {
  static const long long BASE = 10000;
  static const int BW = 4;
  vector<long long> digits;
  Long(long long a = 0) {
    digits.push_back(a);
    Normalize();
  }
  void resize(int s) { digits.resize(s); }
  int size() const { return digits.size(); }
  int sign() const { return digits[digits.size() - 1] > 0 ? 1 : (digits[digits.size() - 1] < 0 ? -1 : 0); }
  Long abs() const {
    Long ret = *this;
    return ret.sign() >= 0 ? ret : -ret;;
  }
  long long operator[](int index) const { return digits[index]; }
  long long &operator[](int index) { return digits[index]; }
  bool operator<(const Long &rhs) const {
    const Long &lhs = *this;
    if (lhs.sign() != rhs.sign()) { return lhs.sign() < rhs.sign(); }
    if (lhs.size() != rhs.size()) { return lhs.sign() > 0 ? lhs.size() < rhs.size() : lhs.size() > rhs.size(); }
    for (int i = lhs.size() - 1; i >= 0; i--) {
      if (lhs[i] != rhs[i]) { return lhs[i] < rhs[i]; }
    }
    return false;
  }
  bool operator>(const Long &rhs) const { return rhs < *this; }
  bool operator<=(const Long &rhs) const { return !(rhs < *this); }
  bool operator>=(const Long &rhs) const { return !(*this < rhs); }
  bool operator!=(const Long &rhs) const { return *this < rhs || rhs < *this; }
  bool operator==(const Long &rhs) const { return !(*this < rhs) && !(rhs < *this); }

  Long &Normalize() {
    int s = 1;
    while (digits[size() - 1] <= -BASE) {
      ll v = digits[size() - 1] / BASE;
      digits.push_back(v);
      digits[size() - 2] -= v * BASE;
    }     
    for (int i = 0; i < size(); i++) {
      if (i == size() - 1 && digits[i] < 0) {
        goto minus;
      } else if (digits[i] < 0) {
        long long a = -((digits[i] + 1) / BASE) + 1;
        digits[i] = a * BASE + digits[i];
        digits[i + 1] -= a;
      } else if (digits[i] >= BASE) {
        if (i == size() - 1) { digits.push_back(0); }
        long long a = digits[i] / BASE;
        digits[i] = digits[i] % BASE;
        digits[i + 1] += a;
      }
      assert(0 <= digits[i] && digits[i] < BASE);
      if (digits[i] != 0) { s = i + 1; }
    }
    assert(0 <= digits[s - 1] && digits[s - 1] < BASE);
    assert(s == 1 || digits[s - 1] != 0);
    resize(s);
    return *this;
minus:
    s = 1;
    for (int i = size() - 2; i >= 0; i--) {
      digits[i + 1] += 1;
      digits[i] -= BASE;
      if (digits[i + 1] != 0) { s = max(s, i + 2); }
      assert(digits[i + 1] <= 0);
      assert(digits[i] <= 0);
    }
    resize(s);
    return *this;
  }
  Long &convert(const string &str) {
    if (str.length() == 0) { return *this; }
    int s = str[0] != '-' ? 1 : -1;
    int sw = s == -1 ? 1 : 0;
    digits = vector<long long>((str.size() - 1 - sw) / BW + 1);
    int i = (str.size() - sw) % BW;
    int index = digits.size() - 1;
    if (i > 0) { i -= BW; }
    for (; i < (int)str.size() - sw; i+= BW) {
      long long a = 0;
      for (int j = 0; j < BW; j++) {
        a = 10 * a + (i + j + sw >= sw ? str[i + j + sw] - '0' : 0);
      }
      digits[index--] = a * s;
    }
    return Normalize();
  }
  void Print() {
    int s = sign();
    printf("%lld", digits[size() - 1]);
    for (int i = size() - 2; i >= 0; i--) {
      assert(BW == 4);
      printf("%04lld", digits[i] * s);
    }
  }
  Long operator+(const Long &rhs) const {
    Long ret = *this;
    if (ret.size() < rhs.size()) { ret.resize(rhs.size()); }
    for (int i = 0; i < rhs.size(); i++) { ret[i] += rhs[i]; }
    return ret.Normalize();
  }
  Long operator-(const Long &rhs) const {
    //assert(*this >= rhs);
    Long ret = *this;
    if (ret.size() < rhs.size()) { ret.resize(rhs.size()); }
    for (int i = 0; i < rhs.size(); i++) { ret[i] -= rhs[i]; }
    return ret.Normalize();
  }
  Long operator*(const Long &rhs) const {
    const Long &lhs = *this;
    Long ret;
    ret.resize(this->size() + rhs.size());
    for (int i = 0; i < lhs.size(); i++) {
      for (int j = 0; j < rhs.size(); j++) {
        ret[i + j] += lhs[i] * rhs[j];
      }
    }
    return ret.Normalize();
  }
  Long operator/(const Long &rhs) const {
    return this->divmod(rhs).first;
  }
  Long operator%(const Long &rhs) const {
    return this->divmod(rhs).second;
  }
  Long operator-() const {
    return *this * -1;
  }
  Long &operator+=(const Long &rhs) {
    return *this = *this + rhs;
  }
  Long &operator-=(const Long &rhs) {
    return *this = *this - rhs;
  }
  Long &operator*=(const Long &rhs) {
    return *this = *this * rhs;
  }
  Long &operator/=(const Long &rhs) {
    return *this = *this / rhs;
  }
  Long &operator%=(const Long &rhs) {
    return *this = *this % rhs;
  }
  pair<Long, long long> divmodll(long long rhs) const {
    Long ret = *this;
    long long c = 0;
    long long t;
    for (int i = ret.size() - 1; i >= 0; i--) {
      t = BASE * c + ret[i];
      ret[i] = t / rhs;
      c = t % rhs;
    }
    return make_pair(ret.Normalize(), c);
  }
  pair<Long, Long> divmod(Long rhs) const {
    Long lhs = *this;
    if (lhs.size() < rhs.size()) { return pair<Long, Long>(0, lhs); }
    int s = lhs.sign() * rhs.sign();
    lhs = lhs.abs(); rhs = rhs.abs();
    long long F = BASE / (rhs[rhs.size() - 1] + 1);  // multiplying good-factor
    lhs = lhs * F; rhs = rhs * F;
    Long ret;
    ret.resize(lhs.size() - rhs.size() + 1);
    for (int k = ret.size() - 1, i = lhs.size() - 1; k >= 0; k--, i--) {
      ret[k] = (i + 1 < lhs.size() ? lhs[i + 1] : 0) * BASE + lhs[i];
      ret[k] /= rhs[rhs.size() - 1];
      Long t;
      t.resize(k + rhs.size());
      for (int m = 0; m < rhs.size(); m++) {
        t[k + m] = ret[k] * rhs[m];
      }
      t.Normalize();
      while (lhs < t) {
        ret[k] -= 1;
        for (int m = 0; m < rhs.size(); m++) {
          t[k + m] -= rhs[m];
        }
        t.Normalize();
      }
      lhs = lhs - t;
    }
    return make_pair(ret.Normalize() * s, lhs.divmodll(F).first * s);
  }
};
ostream &operator<<(ostream &os, const Long &rhs) {
  int s = rhs.sign();
  os << rhs[rhs.size() - 1];
  for (int i = rhs.size() - 2; i >= 0; i--) {
    os << setw(Long::BW) << setfill('0') << rhs[i] * s;
  }
  return os;
}
istream &operator>>(istream &is, Long &rhs) {
  string s;
  is >> s;
  rhs.convert(s);
  return is;
}
bool isInt(double a) {
  return EQ(a-round(a),0);
}
bool isSquare(ll d) {
  return isInt(sqrt(d));
}
pair<Long,Long> pell(ll d_) {
  assert(!isSquare(d_));
  Long d(d_);
  Long p(1),k(1),x1(1),y(0),sd(sqrt(d_));
  Long x(0);
  while(k!=Long(1)||y==Long(0)) {
    p = k*(p/k+1)-p;
    p = p-(p-sd)/k*k;

    x = (p*x1+d*y)/k.abs();
    y = (p*y+x1)/k.abs();
    k = (p*p-d)/k;

    x1 = x;
  }
  return make_pair(x,y);
}

int main() {
  int n;
  int T = 0;
  while(cin>>n,n) {
    int n2 = n*2;
    ll a,b;
    if (isSquare(n2)) {
      a = int(sqrt(n2)+EPS);
      b = 1;
    } else {
      pair<Long,Long> p = pell(2*n);
      stringstream ss;
      ss<<p.first;ss>>a;ss.clear();
      ss<<p.second;ss>>b;
    }
    printf("Case %d: %lld %lld\n",++T,a,b);
  }
}
accuracy: 1
time_ms: 4400
memory_kb: 984
final_rank: 6