結果
問題 | No.1006 Share an Integer |
ユーザー |
|
提出日時 | 2020-08-29 16:21:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,348 ms / 2,000 ms |
コード長 | 1,691 bytes |
コンパイル時間 | 1,841 ms |
コンパイル使用メモリ | 180,124 KB |
実行使用メモリ | 42,356 KB |
最終ジャッジ日時 | 2024-11-14 14:12:51 |
合計ジャッジ時間 | 14,955 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>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 1000000000000000000typedef pair<ll, ll> pll;typedef pair<int, int> pint;const ll MAX = 3000000;vector<ll> SPF(ll n) {vector<ll> 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 prime_factorize(ll N, vector<ll> &spf, vector<ll> &dp) {if (dp[N] != -1) {return dp[N];}map<ll, ll> ma;while (N != 1) {ma[spf[N]]++;N /= spf[N];}ll d = 1;for (auto p : ma) {d *= (p.second + 1);}return dp[N] = d;}int main() {cin.tie(0);ios::sync_with_stdio(false);int X;cin >> X;vector<ll> spf = SPF(MAX), dp(X + 5, -1);vector<pll> ans;ll miv = INF;for (int a = 1; a < X; a++) {int b = X - a;if (a > b)break;ll tmp = abs(b - a + prime_factorize(a, spf, dp) -prime_factorize(b, spf, dp));miv = min(miv, tmp);}for (int a = 1; a < X; a++) {int b = X - a;ll tmp = abs(b - a + prime_factorize(a, spf, dp) -prime_factorize(b, spf, dp));if (tmp == miv) {ans.push_back({a, b});}}rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }}