Files
contests/misc/tlbdhsg/stones_t.cpp

32 lines
709 B
C++

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
long long n;
if (!(cin >> n))
return 0;
// The minimum sum a+b for a*b >= n occurs when a and b are close to sqrt(n)
long long a = sqrt(n);
long long b = (n + a - 1) / a; // Ceiling division
// We check if (a+1) provides a better sum
// though mathematically, the first integer b near sqrt(n) is usually it.
long long res_a = a, res_b = b;
// Check the neighbor just in case of rounding issues with sqrt
long long a2 = a + 1;
long long b2 = (n + a2 - 1) / a2;
if (a2 + b2 < res_a + res_b) {
res_a = a2;
res_b = b2;
}
cout << res_a << " " << res_b << endl;
return 0;
}