結果
| 問題 | No.937 Ultra Sword | 
| コンテスト | |
| ユーザー |  maspy | 
| 提出日時 | 2020-03-28 16:50:54 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 868 bytes | 
| コンパイル時間 | 303 ms | 
| コンパイル使用メモリ | 12,160 KB | 
| 実行使用メモリ | 24,072 KB | 
| 最終ジャッジ日時 | 2025-01-02 11:46:53 | 
| 合計ジャッジ時間 | 20,559 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 WA * 27 | 
ソースコード
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import reduce
U = 10 ** 5
N, *A = map(int, read().split())
num_count = [0] * (U + 1)
for x in A:
    num_count[x] += 1
save_cost = [0] * (U + 1)
for d in range(2, U + 1):
    save_cost[d] = sum((n - n // d) * num_count[n] for n in range(d, U + 1, d))
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        LA = a.bit_length()
        LB = b.bit_length()
        a ^= b << (LA - LB)
        if a < b:
            a, b = b, a
    return a
g = reduce(gcd, A)
cand = [g]
for _ in range(17):
    cand += [(x << 1) ^ g for x in cand]
max_save = 0
for d in cand:
    if 1 <= d <= U:
        x = save_cost[d]
        if max_save < x:
            max_save = x
answer = sum(A) - max_save
print(answer)
            
            
            
        