結果
問題 | No.1006 Share an Integer |
ユーザー |
|
提出日時 | 2020-08-29 15:45:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,743 bytes |
コンパイル時間 | 2,012 ms |
コンパイル使用メモリ | 182,356 KB |
実行使用メモリ | 56,836 KB |
最終ジャッジ日時 | 2024-11-14 14:10:20 |
合計ジャッジ時間 | 35,890 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 TLE * 11 |
ソースコード
#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;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;}map<ll, ll> prime_factorize(ll N, vector<ll> spf) {map<ll, ll> res;while (N != 1) {res[spf[N]]++;N /= spf[N];}return res;}int main() {cin.tie(0);ios::sync_with_stdio(false);int X;cin >> X;map<ll, ll> ma;vector<ll> spf = SPF(X + 5), dp(X + 5);vector<pll> ans;ll miv = INF;for (int a = 1; a < X; a++) {int b = X - a;if (b < a)break;map<ll, ll> aa = prime_factorize(a, spf);map<ll, ll> bb = prime_factorize(b, spf);ll da = 1, db = 1;for (auto m : aa) {da *= (m.second + 1);}for (auto m : bb) {db *= (m.second + 1);}ll tmp = abs(b - a + da - db);miv = min(miv, tmp);dp[a] = da, dp[b] = db;}for (int a = 1; a < X; a++) {int b = X - a;ll da = dp[a], db = dp[b];ll tmp = abs(b - a + da - db);if (tmp == miv) {ans.push_back({a, b});}}rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }}