結果

問題 No.1006 Share an Integer
ユーザー rinrinta121rinrinta121
提出日時 2020-08-27 23:28:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,182 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 170,672 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-26 06:27:38
合計ジャッジ時間 5,207 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 3 ms
6,940 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()

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

map<ll,ll> prime_factors(ll n){
    map<ll,ll> res;
    if(n == 1){
        res[n] = 1;
        return res;
    }
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1){
        res[n] = 1;
    }
    return res;
}

ll num_of_divisor(ll n){
    map<ll,ll> m = prime_factors(n);
    ll res = 1;
    for(auto i : m){
        res *= (i.second+1);
    }
    return res;
}

int main()
{
    ll x; cin >> x;
    ll num = INF;
    for(int i = 1; i < x; i++){
        ll a = i,b = x - i;
        num = min(abs(a - num_of_divisor(a) - b + num_of_divisor(b)),num);
    }
    for(int i = 1; i < x; i++){
        ll a = i,b = x - i;
        if(num == abs(a - num_of_divisor(a) - b + num_of_divisor(b))){
            cout << a << ' ' << b << endl;
        }
    }
}
0