結果

問題 No.1006 Share an Integer
ユーザー rinrinta121rinrinta121
提出日時 2020-08-28 01:47:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,284 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 169,708 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 10:26:29
合計ジャッジ時間 3,267 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 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 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 51 ms
5,376 KB
testcase_12 AC 79 ms
5,376 KB
testcase_13 AC 84 ms
5,376 KB
testcase_14 AC 83 ms
5,376 KB
testcase_15 AC 72 ms
5,376 KB
testcase_16 AC 39 ms
5,376 KB
testcase_17 AC 51 ms
5,376 KB
testcase_18 AC 74 ms
5,376 KB
testcase_19 AC 70 ms
5,376 KB
testcase_20 AC 75 ms
5,376 KB
testcase_21 AC 84 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
        if(abs(a-b) > 2 * (2*sqrt(x)+1)) continue;
        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(abs(a-b) > 2 * (2*sqrt(x)+1)) continue;
        if(num == abs(a - num_of_divisor(a) - b + num_of_divisor(b))){
            cout << a << ' ' << b << endl;
        }
    }
}
0