結果
問題 | No.1146 土偶Ⅰ |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
import mathdef 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 factorsdef mobius(d):if d == 1:return 1factors = {}temp = dfor i in range(2, int(math.isqrt(temp)) + 1):if i * i > temp:breakif temp % i == 0:factors[i] = 1temp //= iif temp % i == 0:return 0if temp > 1:factors[temp] = 1return (-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 = 0for num in a:if num % d == 0:count += 1c_d[d] = countans = 0for d in all_factors:mu = mobius(d)if mu == 0:continuecount = c_d[d]if count >= 3:ans += mu * (count * (count - 1) * (count - 2) // 6)print(ans)