結果

問題 No.1006 Share an Integer
ユーザー polylogKpolylogK
提出日時 2020-03-11 14:42:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,340 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 14,936 KB
最終ジャッジ日時 2024-04-27 19:15:29
合計ジャッジ時間 4,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
14,936 KB
testcase_01 AC 9 ms
7,808 KB
testcase_02 AC 8 ms
7,824 KB
testcase_03 AC 7 ms
7,836 KB
testcase_04 AC 8 ms
7,852 KB
testcase_05 AC 7 ms
7,828 KB
testcase_06 AC 7 ms
7,852 KB
testcase_07 AC 8 ms
7,824 KB
testcase_08 AC 7 ms
7,916 KB
testcase_09 AC 8 ms
7,760 KB
testcase_10 AC 8 ms
7,936 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 <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(1e6 + 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