結果

問題 No.1006 Share an Integer
ユーザー lyululyulu
提出日時 2020-03-06 22:29:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 2,217 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 184,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-04 11:16:49
合計ジャッジ時間 3,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;

int f(int n, v1i v){
    map<int, int> m;
    int a = n, s = 1;
    rep(i, v.size()){
        if(v[i] > pow(n, 0.5)) break;
        int b = 0;
        while(a % v[i] == 0){
            a /= v[i];
            ++b;
        }
        if(b != 0) m[v[i]] = b;
        if(a == 1) break;
    }
    if(a != 1 && !m.count(a)) m[a] = 1;
    for(auto c: m){
        s *= c.se+1;
    }
    return n-s;
}

int main() {
    v1i r = {2};
    rep(i, 1e3*2){
        if(i > 2){
            bool b = 1;
            rep(j, r.size()){
                if(r[j] > pow(i, 0.5)) break;
                else if(i % r[j] == 0){
                    b = 0;
                    break;
                }
            }
            if(b) r.push_back(i);
        }
    }
    int x, m;
    cin >> x;
    vector<pii> v;
    if(x < 2000){
        rep(i, x/2){
            v.push_back(make_pair(abs(f(i+1, r) - f(x-i-1, r)), i+1));
            if(i+1 != x-i-1) v.push_back(make_pair(abs(f(i+1, r) - f(x-i-1, r)), x-i-1));
        }
    }
    else{
        for(int i = x/2-1000; i <= x/2; ++i){
            v.push_back(make_pair(abs(f(i, r) - f(x-i, r)), i));
            if(i != x-i) v.push_back(make_pair(abs(f(i, r) - f(x-i, r)), x-i));
        }
    }
    sort(v.begin(), v.end());
    m = v[0].fi;
    rep(i, v.size()) if(v[i].fi == m) cout << v[i].se << " " << x-v[i].se << endl;
    return 0;
}
0