結果

問題 No.1259 スイッチ
ユーザー msm1993msm1993
提出日時 2020-10-23 15:41:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,879 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 170,720 KB
実行使用メモリ 18,824 KB
最終ジャッジ日時 2023-09-28 15:27:10
合計ジャッジ時間 6,138 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
18,628 KB
testcase_01 AC 18 ms
18,592 KB
testcase_02 AC 18 ms
18,628 KB
testcase_03 AC 18 ms
18,696 KB
testcase_04 AC 18 ms
18,508 KB
testcase_05 AC 19 ms
18,316 KB
testcase_06 AC 19 ms
18,612 KB
testcase_07 AC 19 ms
18,368 KB
testcase_08 AC 19 ms
18,668 KB
testcase_09 AC 19 ms
18,320 KB
testcase_10 AC 24 ms
18,480 KB
testcase_11 AC 28 ms
18,760 KB
testcase_12 AC 25 ms
18,548 KB
testcase_13 AC 22 ms
18,484 KB
testcase_14 AC 23 ms
18,748 KB
testcase_15 AC 22 ms
18,364 KB
testcase_16 AC 27 ms
18,624 KB
testcase_17 AC 23 ms
18,496 KB
testcase_18 AC 27 ms
18,496 KB
testcase_19 AC 27 ms
18,816 KB
testcase_20 AC 25 ms
18,564 KB
testcase_21 AC 28 ms
18,508 KB
testcase_22 AC 21 ms
18,348 KB
testcase_23 AC 27 ms
18,288 KB
testcase_24 AC 25 ms
18,796 KB
testcase_25 AC 25 ms
18,824 KB
testcase_26 AC 28 ms
18,540 KB
testcase_27 AC 26 ms
18,484 KB
testcase_28 AC 26 ms
18,824 KB
testcase_29 AC 27 ms
18,668 KB
testcase_30 AC 23 ms
18,544 KB
testcase_31 AC 26 ms
18,800 KB
testcase_32 AC 21 ms
18,512 KB
testcase_33 AC 30 ms
18,300 KB
testcase_34 AC 24 ms
18,768 KB
testcase_35 AC 26 ms
18,800 KB
testcase_36 AC 25 ms
18,512 KB
testcase_37 AC 25 ms
18,744 KB
testcase_38 AC 25 ms
18,820 KB
testcase_39 AC 28 ms
18,672 KB
testcase_40 AC 28 ms
18,796 KB
testcase_41 AC 27 ms
18,816 KB
testcase_42 AC 29 ms
18,584 KB
testcase_43 AC 24 ms
18,748 KB
testcase_44 AC 27 ms
18,500 KB
testcase_45 AC 28 ms
18,508 KB
testcase_46 AC 24 ms
18,628 KB
testcase_47 AC 29 ms
18,764 KB
testcase_48 AC 24 ms
18,500 KB
testcase_49 AC 28 ms
18,680 KB
testcase_50 AC 24 ms
18,752 KB
testcase_51 AC 21 ms
18,624 KB
testcase_52 AC 28 ms
18,632 KB
testcase_53 AC 23 ms
18,696 KB
testcase_54 AC 28 ms
18,764 KB
testcase_55 AC 22 ms
18,672 KB
testcase_56 AC 23 ms
18,588 KB
testcase_57 AC 27 ms
18,588 KB
testcase_58 AC 24 ms
18,548 KB
testcase_59 AC 26 ms
18,824 KB
testcase_60 AC 28 ms
18,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** mod int ***/

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/*** mod int ここまで ***/

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(1000005);

void Main(){
    int n, m; ll k; cin >> n >> k >> m;
    mint ans = 0;
    for(int i = 1; i <= n; i++){
        if(k % i == 0) {
            ans += comb.fact[n-1] * comb.ifact[n-i] * ((mint)n).pow(n-i);
            // cout << i << ": ";
            // cout << comb.fact[n-1] * comb.ifact[n-i] * ((mint) n).pow(n-i) << endl;
        }
    }
    mint tot = ((mint)n).pow(n);
    if(m != 1) ans = (tot - ans) / (n-1);
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}
0