結果

問題 No.644 G L C C D M
ユーザー vwxyzvwxyz
提出日時 2021-08-11 23:23:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 66,088 KB
最終ジャッジ日時 2023-10-26 01:24:38
合計ジャッジ時間 2,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,576 KB
testcase_01 AC 37 ms
53,576 KB
testcase_02 AC 38 ms
53,576 KB
testcase_03 AC 40 ms
53,576 KB
testcase_04 AC 37 ms
53,576 KB
testcase_05 AC 38 ms
53,576 KB
testcase_06 AC 38 ms
53,576 KB
testcase_07 AC 37 ms
53,576 KB
testcase_08 AC 42 ms
59,368 KB
testcase_09 AC 42 ms
59,368 KB
testcase_10 AC 44 ms
59,760 KB
testcase_11 AC 49 ms
62,400 KB
testcase_12 AC 49 ms
62,400 KB
testcase_13 AC 49 ms
62,404 KB
testcase_14 AC 47 ms
62,400 KB
testcase_15 AC 47 ms
62,388 KB
testcase_16 AC 47 ms
62,388 KB
testcase_17 AC 37 ms
53,580 KB
testcase_18 AC 37 ms
53,580 KB
testcase_19 AC 38 ms
53,580 KB
testcase_20 AC 38 ms
53,580 KB
testcase_21 AC 48 ms
62,388 KB
testcase_22 AC 57 ms
66,020 KB
testcase_23 AC 56 ms
66,016 KB
testcase_24 AC 58 ms
66,088 KB
testcase_25 AC 56 ms
66,016 KB
testcase_26 AC 57 ms
66,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Mebius(N):
    mebius=[1]*(N+1)
    mebius[0]=0
    is_prime=[True]*(N+1)
    is_prime[0]=False
    is_prime[1]=False
    for p in range(2,N+1):
        if is_prime[p]:
            for pp in range(p,N+1,p):
                mebius[pp]*=-1
                is_prime[pp]=False
            for pp in range(p**2,N+1,p**2):
                mebius[pp]=0
    return mebius

N,M=map(int,input().split())
ans=0
if N>=M:
    Me=Mebius(N)
    mod=10**9+7
    for i in range(1,N+1):
        if i%M:
            continue
        ans+=Me[i//M]*(N//i)*(N//i-1)
        ans%=mod
    for i in range(1,N-1):
        ans*=i
        ans%=mod
print(ans)
0