找到一组 使 最接近与 即可,由于 增长的很快,我们枚举 ,可以 求出符合条件的 ,最后将答案取 即可。
#include<bits/stdc++.h>
#define int long long
#define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 3e5 + 10;
const int M = 1e3 + 10;
int mod = 1e9 + 7;
int a[N], fac[20];
int check(int x) {
if (x == 2) return 0;
return 1;
}
void solve() {
int n;
cin >> n;
fac[0] = 1;
int minn = 1e18, ansx, ansy;
for (int i = 1; i <= 20; i++) fac[i] = fac[i - 1] * i;
for (int i = 1; i <= 20; i++) {
int x = i, y;
int sum = 0;
if (!check(x)) continue;
if (x == 1) sum = n, y = 1;
else {
int k1 = n / (fac[x] - 1), k2 = (n + fac[x] - 2) / (fac[x] - 1);
if (!check(k1)) sum = abs(n - k2 * (fac[x] - 1)), y = k2;
else if (!check(k2)) sum = abs(n - k1 * (fac[x] - 1)), y = k1;
else {
if (abs(n - k1 * (fac[x] - 1)) < abs(n - k2 * (fac[x] - 1))) sum = abs(
n - k1 * (fac[x] - 1)), y = k1;
else sum = abs(n - k2 * (fac[x] - 1)), y = k2;
}
}
if (sum < minn) {
minn = sum;
ansx = x;
ansy = y;
}
}
cout << ansx << " " << ansy << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _;
_ = 1;
//cin>>_;
while (_--) {
solve();
}
}