結果

問題 No.1146 土偶Ⅰ
ユーザー lam6er
提出日時 2025-03-20 21:08:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,988 KB
実行使用メモリ 74,544 KB
最終ジャッジ日時 2025-03-20 21:08:24
合計ジャッジ時間 3,217 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def get_factors(x):
    factors = set()
    for i in range(1, int(math.isqrt(x)) + 1):
        if x % i == 0:
            factors.add(i)
            factors.add(x // i)
    return factors

def mobius(d):
    if d == 1:
        return 1
    factors = {}
    temp = d
    for i in range(2, int(math.isqrt(temp)) + 1):
        if i * i > temp:
            break
        if temp % i == 0:
            factors[i] = 1
            temp //= i
            if temp % i == 0:
                return 0
    if temp > 1:
        factors[temp] = 1
    return (-1) ** len(factors)

n = int(input())
a = [int(input()) for _ in range(n)]

all_factors = set()
for num in a:
    factors = get_factors(num)
    all_factors.update(factors)

c_d = {}
for d in all_factors:
    count = 0
    for num in a:
        if num % d == 0:
            count += 1
    c_d[d] = count

ans = 0
for d in all_factors:
    mu = mobius(d)
    if mu == 0:
        continue
    count = c_d[d]
    if count >= 3:
        ans += mu * (count * (count - 1) * (count - 2) // 6)

print(ans)
0