結果

問題 No.644 G L C C D M
ユーザー maspymaspy
提出日時 2020-03-31 20:35:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 8,980 KB
最終ジャッジ日時 2023-09-07 07:47:33
合計ジャッジ時間 2,566 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,796 KB
testcase_01 AC 21 ms
8,896 KB
testcase_02 AC 19 ms
8,712 KB
testcase_03 AC 20 ms
8,920 KB
testcase_04 AC 21 ms
8,656 KB
testcase_05 AC 19 ms
8,952 KB
testcase_06 AC 20 ms
8,980 KB
testcase_07 AC 19 ms
8,960 KB
testcase_08 AC 21 ms
8,864 KB
testcase_09 AC 22 ms
8,864 KB
testcase_10 AC 21 ms
8,688 KB
testcase_11 AC 21 ms
8,960 KB
testcase_12 AC 22 ms
8,812 KB
testcase_13 AC 24 ms
8,908 KB
testcase_14 AC 23 ms
8,940 KB
testcase_15 AC 21 ms
8,704 KB
testcase_16 AC 23 ms
8,616 KB
testcase_17 AC 22 ms
8,716 KB
testcase_18 AC 39 ms
8,724 KB
testcase_19 AC 20 ms
8,652 KB
testcase_20 AC 21 ms
8,700 KB
testcase_21 AC 22 ms
8,584 KB
testcase_22 AC 50 ms
8,916 KB
testcase_23 AC 51 ms
8,868 KB
testcase_24 AC 51 ms
8,908 KB
testcase_25 AC 48 ms
8,904 KB
testcase_26 AC 49 ms
8,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache

N, M = map(int, read().split())
MOD = 10**9 + 7


@lru_cache(None)
def f(N):
    """ count 1 <= a < b <= N s.t. gcd(a,b) == 1"""
    if N <= 1:
        return 0
    ret = N * (N - 1) // 2
    sqN = int(N ** .5)
    for d in range(2, N + 1):
        n = N // d
        if n <= sqN:
            break
        ret -= f(n)
    for n in range(1, sqN + 1):
        cnt = (N // n) - (N // (n + 1))
        ret -= f(n) * cnt
    return ret


x = 2 * f(N // M) % MOD
for i in range(1, N - 1):
    x *= i
    x %= MOD
print(x)
0