結果

問題 No.644 G L C C D M
ユーザー vwxyzvwxyz
提出日時 2021-08-11 23:26:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 11,828 KB
実行使用メモリ 11,508 KB
最終ジャッジ日時 2023-10-26 01:26:55
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,128 KB
testcase_01 AC 29 ms
10,128 KB
testcase_02 AC 28 ms
10,128 KB
testcase_03 AC 29 ms
10,128 KB
testcase_04 AC 28 ms
10,128 KB
testcase_05 AC 27 ms
10,128 KB
testcase_06 AC 27 ms
10,128 KB
testcase_07 AC 27 ms
10,128 KB
testcase_08 AC 27 ms
10,128 KB
testcase_09 AC 28 ms
10,136 KB
testcase_10 AC 27 ms
10,140 KB
testcase_11 AC 30 ms
10,192 KB
testcase_12 AC 31 ms
10,232 KB
testcase_13 AC 38 ms
10,232 KB
testcase_14 AC 34 ms
10,232 KB
testcase_15 AC 32 ms
10,232 KB
testcase_16 AC 31 ms
10,208 KB
testcase_17 AC 29 ms
10,128 KB
testcase_18 AC 28 ms
10,128 KB
testcase_19 AC 28 ms
10,128 KB
testcase_20 AC 28 ms
10,128 KB
testcase_21 AC 34 ms
10,232 KB
testcase_22 AC 140 ms
11,508 KB
testcase_23 AC 117 ms
11,508 KB
testcase_24 AC 115 ms
11,508 KB
testcase_25 AC 99 ms
11,508 KB
testcase_26 AC 98 ms
11,508 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