結果

問題 No.2828 Remainder Game
ユーザー ぬるぽ
提出日時 2024-08-02 22:04:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 29,656 KB
平均クエリ数 1.00
最終ジャッジ日時 2024-08-02 22:04:37
合計ジャッジ時間 4,938 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy, copy
import sys
import io
from typing import Optional


import time
from random import randrange, randint, random, uniform
import sys, io
from collections import deque, defaultdict
import heapq
from collections import Counter
import math
from math import gcd
from functools import lru_cache

from itertools import combinations, permutations
from bisect import bisect_left, bisect_right

from itertools import groupby
from itertools import accumulate

from math import factorial

import decimal
import math

# from sortedcontainers import SortedList

# import pypyjit
# pypyjit.set_param("max_unroll_recursion=-1")

sys.setrecursionlimit(1000000000)
sys.set_int_max_str_digits(1000000000)

start_time = time.time()


N = int(input())


@lru_cache(maxsize=None)
def rec(n):

    if n == 1:
        return 0

    num = 0
    cnt = 0
    for M in range(1, N + 1):
        if gcd(n, M) == n:
            cnt += 1
            continue
        num += rec(gcd(n, M))
    num += N

    #    print(n, cnt)
    return num * 1 / (N - cnt)


print(rec(N))
0