結果

問題 No.1006 Share an Integer
ユーザー face4face4
提出日時 2020-03-06 21:46:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 71,708 KB
実行使用メモリ 13,384 KB
最終ジャッジ日時 2024-04-22 06:26:23
合計ジャッジ時間 2,391 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 47 ms
9,088 KB
testcase_12 AC 92 ms
12,800 KB
testcase_13 AC 97 ms
13,260 KB
testcase_14 AC 88 ms
13,384 KB
testcase_15 AC 75 ms
11,904 KB
testcase_16 AC 36 ms
7,552 KB
testcase_17 AC 48 ms
9,344 KB
testcase_18 AC 73 ms
11,904 KB
testcase_19 AC 72 ms
11,648 KB
testcase_20 AC 80 ms
12,288 KB
testcase_21 AC 93 ms
13,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

typedef pair<int,int> pii;

int count[2000001] = {};
bool np[2000001] = {};

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) count[i] = 1;
    for(int i = 2; i <= n; i++){
        if(np[i])   continue;
        for(int j = i; j <= n; j += i){
            np[j] = true;
            int tmp = 0, cp = j;
            while(cp%i == 0)    tmp++, cp /= i;
            count[j] *= ++tmp;
        }
    }
    int tmp = 1<<30;
    vector<int> ans;
    for(int i = 1; i < n; i++){
        int score = abs((i-count[i])-(n-i-count[n-i]));
        if(score > tmp) continue;
        if(score < tmp) ans.clear();
        ans.push_back(i);
        tmp = score;
    }
    for(int i : ans)    cout << i << " " << n-i << endl;
    return 0;
}
0