結果
| 問題 | No.1259 スイッチ | 
| コンテスト | |
| ユーザー |  rlangevin | 
| 提出日時 | 2023-10-12 00:07:17 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 81 ms / 2,000 ms | 
| コード長 | 685 bytes | 
| コンパイル時間 | 229 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 76,500 KB | 
| 最終ジャッジ日時 | 2024-09-14 00:05:29 | 
| 合計ジャッジ時間 | 6,615 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 61 | 
ソースコード
N, K, M = map(int, input().split())
mod = 10 ** 9 + 7
n = 10 ** 6 + 5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod
def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod
now = 0
for i in range(1, N + 1):
    if K % i == 0:
        now += fact[N - 1] * invfact[N - i] * pow(N, N - i, mod)
        now %= mod
        
if M == 1:
    print(now)
    exit()
    
ans = (pow(N, N, mod) - now) * pow(N - 1, mod - 2, mod)
print(ans % mod)
            
            
            
        