結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー ShirotsumeShirotsume
提出日時 2021-11-05 22:17:25
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,329 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 124,688 KB
最終ジャッジ日時 2023-08-07 23:12:34
合計ジャッジ時間 15,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 142 ms
93,272 KB
testcase_02 AC 138 ms
93,180 KB
testcase_03 AC 146 ms
93,036 KB
testcase_04 AC 149 ms
93,024 KB
testcase_05 AC 149 ms
93,168 KB
testcase_06 AC 143 ms
93,356 KB
testcase_07 AC 144 ms
93,620 KB
testcase_08 AC 140 ms
92,996 KB
testcase_09 AC 144 ms
93,316 KB
testcase_10 AC 155 ms
93,420 KB
testcase_11 AC 137 ms
93,044 KB
testcase_12 AC 140 ms
93,228 KB
testcase_13 AC 516 ms
124,068 KB
testcase_14 AC 548 ms
123,956 KB
testcase_15 AC 511 ms
124,176 KB
testcase_16 AC 512 ms
124,072 KB
testcase_17 AC 516 ms
123,812 KB
testcase_18 AC 404 ms
123,740 KB
testcase_19 AC 435 ms
124,324 KB
testcase_20 AC 518 ms
122,868 KB
testcase_21 AC 520 ms
122,856 KB
testcase_22 AC 1,825 ms
123,836 KB
testcase_23 AC 209 ms
121,436 KB
testcase_24 AC 200 ms
121,440 KB
testcase_25 AC 414 ms
124,072 KB
権限があれば一括ダウンロードができます

ソースコード

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()
    if X == 1:
        return ret
    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