結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー |
![]() |
提出日時 | 2025-04-15 23:17:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 713 ms / 2,000 ms |
コード長 | 1,771 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 81,776 KB |
実行使用メモリ | 150,348 KB |
最終ジャッジ日時 | 2025-04-15 23:19:16 |
合計ジャッジ時間 | 8,297 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
import sys def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+N])) idx += N max_spf = 10**6 spf = list(range(max_spf + 1)) for i in range(2, int(max_spf**0.5) + 1): if spf[i] == i: for j in range(i*i, max_spf + 1, i): if spf[j] == j: spf[j] = i def factorize(x): factors = {} while x > 1: p = spf[x] while x % p == 0: factors[p] = factors.get(p, 0) + 1 x = x // p return factors cnt = [0] * (max_spf + 2) for a in A: if a == 0: continue factors = factorize(a) divisors = [1] for p in factors: exponents = factors[p] current_length = len(divisors) for e in range(1, exponents + 1): p_power = p ** e for i in range(current_length): divisors.append(divisors[i] * p_power) for d in divisors: if d <= max_spf: cnt[d] += 1 sorted_d = [] for d in range(max_spf, 0, -1): if cnt[d] > 0: sorted_d.append(d) ans = [0] * (N + 2) current_max_s = 0 for d in sorted_d: c = cnt[d] start = current_max_s + 1 end = min(c, N) if start > end: continue for s in range(start, end + 1): if ans[s] == 0: ans[s] = d else: break current_max_s = max(current_max_s, end) if current_max_s >= N: break for K in range(N): s = N - K print(ans[s]) if __name__ == "__main__": main()