結果

問題 No.1006 Share an Integer
ユーザー polylogKpolylogK
提出日時 2020-03-11 14:43:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 86,128 KB
実行使用メモリ 12,152 KB
最終ジャッジ日時 2023-08-10 01:30:43
合計ジャッジ時間 6,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
11,984 KB
testcase_01 AC 16 ms
11,820 KB
testcase_02 AC 12 ms
11,996 KB
testcase_03 AC 13 ms
11,868 KB
testcase_04 AC 16 ms
11,864 KB
testcase_05 AC 16 ms
11,984 KB
testcase_06 AC 14 ms
11,884 KB
testcase_07 AC 13 ms
11,916 KB
testcase_08 AC 14 ms
11,948 KB
testcase_09 AC 14 ms
11,892 KB
testcase_10 AC 14 ms
11,888 KB
testcase_11 AC 289 ms
12,000 KB
testcase_12 AC 478 ms
11,980 KB
testcase_13 AC 529 ms
11,868 KB
testcase_14 AC 535 ms
11,952 KB
testcase_15 AC 433 ms
11,812 KB
testcase_16 AC 218 ms
12,152 KB
testcase_17 AC 282 ms
11,916 KB
testcase_18 AC 443 ms
11,988 KB
testcase_19 AC 435 ms
11,812 KB
testcase_20 AC 452 ms
12,020 KB
testcase_21 AC 538 ms
12,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <iostream>

int main() {
	int n; scanf("%d", &n);

    // pre
    std::vector<int> prime, mip(2e6 + 1); mip[0] = mip[1] = -1;
    for(int i = 2; i < mip.size(); i++) {
        if(mip[i] == 0) {
            mip[i] = i;
            prime.push_back(i);
        }
        
        for(int j = 0; j < prime.size() and prime[j] <= mip[i] and i * prime[j] <= mip.size(); j++) {
            mip[i * prime[j]] = prime[j];
        }
    }

    auto pfact = [&](int x) {
        std::vector<std::pair<int, int>> vec;
        while(x > 1) {
            if(vec.empty() or vec.back().first != mip[x]) {
                vec.push_back({mip[x], 1});
            } else {
                vec.back().second++;
            }
            x /= mip[x];
        }
        return vec;
    };

	int ans = 1 << 30;
	std::vector<std::pair<int, int>> vec;
    for(int A = 1; A < n; A++) {
		int B = n - A;
		
		auto X = pfact(A);
		auto Y = pfact(B);
		
		int x = 1, y = 1;
		for(auto v: X) x *= v.second + 1;
		for(auto v: Y) y *= v.second + 1;

		int tmp = std::abs((A - x) - (B - y));		
		if(ans > tmp) {
			ans = tmp;
			vec.clear();
		}
		
		if(ans == tmp) vec.push_back({A, B});
	}
	
	for(auto v: vec) printf("%d %d\n", v.first, v.second);
    return 0;
}
0