結果

問題 No.1259 スイッチ
ユーザー kk
提出日時 2020-10-22 21:10:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 200,268 KB
実行使用メモリ 18,592 KB
最終ジャッジ日時 2023-09-28 14:52:53
合計ジャッジ時間 11,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 114 ms
12,276 KB
testcase_11 AC 176 ms
17,812 KB
testcase_12 AC 108 ms
11,748 KB
testcase_13 AC 66 ms
8,244 KB
testcase_14 AC 91 ms
10,632 KB
testcase_15 AC 64 ms
8,088 KB
testcase_16 AC 145 ms
15,168 KB
testcase_17 AC 89 ms
10,356 KB
testcase_18 AC 164 ms
16,696 KB
testcase_19 AC 163 ms
16,764 KB
testcase_20 AC 115 ms
12,544 KB
testcase_21 AC 180 ms
17,880 KB
testcase_22 AC 56 ms
7,504 KB
testcase_23 AC 162 ms
16,572 KB
testcase_24 AC 122 ms
13,168 KB
testcase_25 AC 119 ms
12,804 KB
testcase_26 AC 182 ms
18,148 KB
testcase_27 AC 149 ms
15,376 KB
testcase_28 AC 120 ms
12,932 KB
testcase_29 AC 148 ms
15,364 KB
testcase_30 AC 92 ms
10,548 KB
testcase_31 AC 133 ms
14,360 KB
testcase_32 AC 59 ms
7,808 KB
testcase_33 AC 185 ms
18,204 KB
testcase_34 AC 101 ms
11,296 KB
testcase_35 AC 141 ms
14,640 KB
testcase_36 AC 130 ms
13,588 KB
testcase_37 AC 123 ms
13,164 KB
testcase_38 AC 111 ms
12,276 KB
testcase_39 AC 174 ms
17,404 KB
testcase_40 AC 176 ms
17,816 KB
testcase_41 AC 147 ms
15,244 KB
testcase_42 AC 182 ms
18,180 KB
testcase_43 AC 107 ms
11,948 KB
testcase_44 AC 171 ms
17,264 KB
testcase_45 AC 187 ms
18,592 KB
testcase_46 AC 102 ms
11,376 KB
testcase_47 AC 185 ms
18,464 KB
testcase_48 AC 91 ms
10,292 KB
testcase_49 AC 180 ms
18,076 KB
testcase_50 AC 103 ms
11,336 KB
testcase_51 AC 58 ms
7,512 KB
testcase_52 AC 175 ms
17,920 KB
testcase_53 AC 80 ms
9,704 KB
testcase_54 AC 174 ms
17,552 KB
testcase_55 AC 55 ms
7,184 KB
testcase_56 AC 90 ms
10,432 KB
testcase_57 AC 160 ms
16,496 KB
testcase_58 AC 110 ms
12,008 KB
testcase_59 AC 136 ms
14,132 KB
testcase_60 AC 187 ms
18,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

long long solve(int n, int m, long long k) {
  vector<long long> f(n+1), g(n+1);
  f[0] = g[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = f[i-1] * i % MOD;
    g[i] = modpow(f[i], MOD-2, MOD);
  }
  
  long long x = 0;
  for (int i = 1; i <= n; i++) {
    if (k % i) continue;
    long long tmp = f[n-1] * g[n-i] % MOD * modpow(n, n-i, MOD) % MOD;
    x += tmp;
    x %= MOD;
  }

  if (m > 1)
    x = (modpow(n, n, MOD) - x + MOD) % MOD * modpow(n-1, MOD-2, MOD) % MOD;

  return x;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long n, k, m;
  cin >> n >> k >> m;
  cout << solve(n, m, k) << endl;
  
  return 0;
}
0