結果
| 問題 | 
                            No.2829 GCD Divination
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ニックネーム
                         | 
                    
| 提出日時 | 2024-08-02 22:24:12 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 197 ms / 2,000 ms | 
| コード長 | 427 bytes | 
| コンパイル時間 | 185 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 11,008 KB | 
| 最終ジャッジ日時 | 2024-08-02 22:24:16 | 
| 合計ジャッジ時間 | 3,017 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 35 | 
ソースコード
from functools import cache
@cache
def f(n):
    if n==1: return 0
    s = set(); d = {}; x = 0
    for i in range(1,int(n**0.5)+1):
        if n%i==0: s |= {i,n//i}
    s.remove(n); s = sorted(s); m = len(s)
    for i in range(m-1,-1,-1):
        d[s[i]] = (n-1)//s[i]
        for j in range(i+1,m):
            if s[j]%s[i]==0: d[s[i]] -= d[s[j]]
        x += d[s[i]]*f(s[i])
    return (x/n+1)*n/(n-1)
print(f(int(input())))
            
            
            
        
            
ニックネーム