結果

問題 No.1006 Share an Integer
ユーザー mikianaaamikianaaa
提出日時 2020-08-29 15:40:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,705 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 176,808 KB
実行使用メモリ 36,568 KB
最終ジャッジ日時 2024-04-26 22:21:42
合計ジャッジ時間 5,634 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 1000000000000000000
typedef 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;
        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; }
}
0