結果

問題 No.1006 Share an Integer
ユーザー qLethonqLethon
提出日時 2020-03-06 23:14:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,247 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 204,828 KB
実行使用メモリ 21,852 KB
最終ジャッジ日時 2024-04-22 10:27:51
合計ジャッジ時間 5,914 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 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;

template<class INT>
std::vector<INT> get_min_prime_fact_table(INT n){
    std::vector<INT> lp(n + 1), P;
    for (INT i = 2; i <= n; i++){
        if (lp[i] == 0){
            lp[i] = i;
            P.push_back(i);
        }
        for (INT j = 0; j <= P.size() and P[j] <= lp[i] and i * P[j] <= n; j++)
            lp[i * P[j]] = P[j];
    }

    return lp;
}

template<class INT>
std::map<INT, int> prime_factorize(INT n, std::vector<INT> lp){
    std::map<INT, int> res;
    while (n != 1){
        res[lp[n]]++;
        n /= lp[n];
    }

    return res;
}

int main(){
    int x;
    cin >> x;
    auto lp = get_min_prime_fact_table(x);
    vector<int> A(x + 1);
    int ma = 1e9;
    for (int a = 1; a < x; a++){
        auto b = x - a;
        auto pa = prime_factorize(a, lp);
        auto pb = prime_factorize(b, lp);
        int ca = 1, cb = 1;
        for (const auto &[k, v] : pa)
            ca *= (v + 1);
        for (const auto &[k, v] : pb)
            cb *= (v + 1);
        auto s = abs(a - ca - (b - cb));
        A[a] = s;
        ma = min(ma, s); 
    }

    for (int i = 1; i < x; i++){
        if (A[i] == ma){
            cout << i << " " << x - i << endl;
        }
    }
}
0