結果
問題 | No.1006 Share an Integer |
ユーザー | 双六 |
提出日時 | 2020-08-06 15:38:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,601 ms / 2,000 ms |
コード長 | 1,549 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 81,996 KB |
実行使用メモリ | 97,340 KB |
最終ジャッジ日時 | 2024-09-19 18:28:00 |
合計ジャッジ時間 | 30,467 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 178 ms
89,656 KB |
testcase_01 | AC | 242 ms
89,728 KB |
testcase_02 | AC | 1,562 ms
96,000 KB |
testcase_03 | AC | 110 ms
89,344 KB |
testcase_04 | AC | 1,601 ms
95,744 KB |
testcase_05 | AC | 1,521 ms
95,960 KB |
testcase_06 | AC | 1,515 ms
95,416 KB |
testcase_07 | AC | 1,508 ms
95,628 KB |
testcase_08 | AC | 1,499 ms
95,232 KB |
testcase_09 | AC | 1,493 ms
95,632 KB |
testcase_10 | AC | 1,525 ms
95,536 KB |
testcase_11 | AC | 1,564 ms
96,728 KB |
testcase_12 | AC | 1,509 ms
96,696 KB |
testcase_13 | AC | 1,501 ms
96,436 KB |
testcase_14 | AC | 1,512 ms
96,776 KB |
testcase_15 | AC | 1,509 ms
96,832 KB |
testcase_16 | AC | 1,526 ms
96,472 KB |
testcase_17 | AC | 1,529 ms
97,340 KB |
testcase_18 | AC | 1,507 ms
96,168 KB |
testcase_19 | AC | 1,502 ms
96,236 KB |
testcase_20 | AC | 1,487 ms
96,048 KB |
testcase_21 | AC | 1,498 ms
96,784 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) num = 2 * 10 ** 6 + 1 L = [1 for i in range(num)]; L[0] = 0; L[1] = 0 plist = [] for i in range(num): if L[i] == 1: plist.append(i); c = 2 while i * c <= num - 1: L[i * c] = 0; c += 1 def prime_factorization(N): D = defaultdict(int) for i in plist: while N % i == 0: D[i] += 1; N = int(N // i) if N != 1: D[N] += 1 return D #処理内容 def main(): X = int(input()) if X <= 3 * 10 ** 2: L = [] for i in range(1, X): a = i; b = X - i facA = prime_factorization(a) facB = prime_factorization(b) numA = 1; numB = 1 for key, value in facA.items(): numA *= value + 1 for key, value in facB.items(): numB *= value + 1 L.append([abs(a - b - (numA - numB)), a, b]) L.sort() val = L[0][0] for i in range(len(L)): if L[i][0] == val: print(L[i][1], L[i][2]) else: break else: L = [] for i in range(int(X // 2) - 200, int(X // 2) + 200): a = i; b = X - i facA = prime_factorization(a) facB = prime_factorization(b) numA = 1; numB = 1 for key, value in facA.items(): numA *= value + 1 for key, value in facB.items(): numB *= value + 1 L.append([abs(a - b - (numA - numB)), a, b]) L.sort() val = L[0][0] for i in range(len(L)): if L[i][0] == val: print(L[i][1], L[i][2]) else: break if __name__ == '__main__': main()