結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー ShirotsumeShirotsume
提出日時 2021-11-05 22:15:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,295 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 123,452 KB
最終ジャッジ日時 2024-04-24 06:03:29
合計ジャッジ時間 13,034 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,954 ms
122,696 KB
testcase_01 AC 93 ms
82,192 KB
testcase_02 AC 96 ms
83,316 KB
testcase_03 AC 103 ms
85,844 KB
testcase_04 AC 102 ms
85,448 KB
testcase_05 AC 111 ms
86,116 KB
testcase_06 AC 101 ms
86,120 KB
testcase_07 AC 106 ms
86,480 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 99 ms
83,712 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 396 ms
123,452 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 1,680 ms
122,476 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
#N = 入力の最大
N = 1000000 + 100
sieve = [i for i in range(N + 1)]

for i in range(2,N + 1):
    if sieve[i] == i:
        for j in range(2 * i, N + 1, i):
            sieve[j] = i

def prime_fact(X):
    ret = Counter()
    while 1:
        ret[sieve[X]] += 1
        if sieve[X] == X:
            break
        else:
            X //= sieve[X]
    return ret

def divisors(N, b):
    div = [1]
    b[1] += 1
    for p,a in prime_fact(N).items():
        m = len(div)
        for i in range(m):
            for j in range(1, a+1):
                div.append(div[i] * p**j)
                b[div[i] * p ** j] += 1
    
    return b
n = int(input())

a = list(map(int,input().split()))

#K = N - 1のとき答えはmax(a)になる
#ではK = N - 2では?2個残さないといけないので、答えは2個選んだときの最大公約数の最大値
#同様にN - K個選んだ時の最大公約数の最大値になる
#aの約数をマッピングしていく、N - K以上の最大値を探せばよい

b = [0] * (10 ** 6 + 100)
for i in range(n):
    b = divisors(a[i], b)
ans = [0] * (n + 1)
for i in range(10 ** 6 + 99):
    if b[i] != 0:
        ans[b[i]] = i
ans.reverse()
for i in range(n):
    ans[i] = max(ans[i], ans[i - 1])
    print(ans[i])
0