結果
| 問題 |
No.2829 GCD Divination
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-08-04 05:02:06 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 734 ms / 2,000 ms |
| コード長 | 806 bytes |
| コンパイル時間 | 419 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-08-04 05:02:12 |
| 合計ジャッジ時間 | 5,234 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
import sys
input = sys.stdin.readline
from collections import Counter
from math import gcd
N=int(input())
LIST=[]
for i in range(1,round(N**(1/2))+3):
if N%i==0:
LIST.append(i)
LIST.append(N//i)
LIST=sorted(set(LIST))
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(x):
if x==1:
return 0
KO=Counter()
for i in LIST[::-1]:
if i>x:
continue
if x%i != 0:
continue
k=x//i
KO[i]+=k
for j in LIST:
if i%j==0 and j<i:
KO[j]-=KO[i]
score=0
#print(x,KO)
for i in LIST:
if x==i:
break
score+=(calc(i))*KO[i]/(x-1)
#print(x,i,score)
#print("!",score)
return score+x/(x-1)
print(calc(N))
titia