結果

問題 No.1006 Share an Integer
ユーザー bond_cmprogbond_cmprog
提出日時 2020-03-06 22:32:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,370 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 179,752 KB
実行使用メモリ 11,020 KB
最終ジャッジ日時 2024-04-22 08:58:52
合計ジャッジ時間 5,734 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 190 ms
7,528 KB
testcase_12 AC 328 ms
10,592 KB
testcase_13 AC 352 ms
10,964 KB
testcase_14 AC 354 ms
11,020 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 298 ms
9,880 KB
testcase_19 AC 289 ms
9,732 KB
testcase_20 AC 305 ms
10,204 KB
testcase_21 AC 351 ms
10,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> smallest_prime_factors(T n) {

    vector<T> spf(n + 1);
    for (int i = 0; i <= n; i++) spf[i] = i;


    for (T i = 2; i * i <= n; i++) {

        // 素数だったら
        if (spf[i] == i) {

            for (T j = i * i; j <= n; j += i) {

                // iを持つ整数かつまだ素数が決まっていないなら
                if (spf[j] == j) {
                    spf[j] = i;
                }
            }
        }
    }

    return spf;
}

template<typename T>
map<T, T> factorization(T x, vector<T> &spf) {
    map<T, T> ret;
    while (x != 1) {
        ret[spf[x]]++;
        x /= spf[x];
    }
    //sort(ret.begin(), ret.end());
    return ret;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> X;
    auto spf = smallest_prime_factors(X);
    vector<pair<int, int>> ans;
    int ma = INF;
    for(int i=X/2;i>=1;i--){
        auto res1 = factorization(i, spf);
        auto res2 = factorization(X-i, spf);
        int d1  = 1, d2 = 1;
        for(auto x : res1) d1 *= (x.second + 1);
        for(auto x : res2) d2 *= (x.second + 1);
        int f = abs((i - d1) - (X-i - d2));
        if(f == ma){
            ans.emplace_back(i, X-i);
            ans.emplace_back(X-i, i);
        }
        else if(f < ma){
            ma = f;
            ans = vector<pair<int,int>> ();
            ans.emplace_back(i, X-i);
            ans.emplace_back(X-i, i);
        }
    }
    //cout << ma << endl;
    sort(ans.begin(), ans.end());
    for(auto x : ans) cout << x.first << " " << x.second << endl;
}
0