#include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define LL long long #define ld long double #define INF 1000000000000000000 typedef pair PLL; vector SPF(LL n) { vector spf(n + 1); for (int i = 0; i <= n; i++) spf[i] = i; for (LL i = 2; i * i <= n; i++) { if (spf[i] == i) { for (LL j = i * i; j <= n; j += i) { if (spf[j] == j) { spf[j] = i; } } } } return spf; } LL primes(LL x, vector &spf, vector &dp) { if (dp[x] != -1) { return dp[x]; } LL o = x; vector a; while (x != 1) { a.push_back(spf[x]); x /= spf[x]; } LL d = 1; int n = a.size(); for (int i = 0, j = 0; i < n; i = j) { while (j < n and a[i] == a[j]) j++; d *= (j - i + 1); } return dp[o] = d; } constexpr LL MAX = 3000000; int main() { LL X; cin >> X; auto spf = SPF(MAX); LL maxV = 1e18; vector dp(MAX, -1); for (LL a = 1; a < X; a++) { LL b = X - a; LL val = abs((b - a) + (primes(a, spf, dp) - primes(b, spf, dp))); if (val < maxV) { maxV = val; } } vector ret; for (LL a = 1; a < X; a++) { LL b = X - a; LL val = abs((b - a) + (primes(a, spf, dp) - primes(b, spf, dp))); if (val == maxV) { ret.push_back(make_pair(a, b)); } } sort(all(ret)); for (auto x : ret) cout << x.first << " " << x.second << endl; }