結果

問題 No.391 CODING WAR
ユーザー hashiryo
提出日時 2018-04-25 14:59:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 58,360 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 21:02:37
合計ジャッジ時間 1,537 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//


#include <iostream>
//#include <fstream>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

ll mod_pow(ll a,ll r){
    if(r==0)
        return 1;
    //cout << a << " " << r <<endl;
    ll res=mod_pow(a*a%MOD,r/2);
    if(r&1){
        res=res*a%MOD;
    }
    return res;
}


ll mod_inv(ll a){
    //cout <<"inv "<< a << endl;
    return mod_pow(a,MOD-2);
}

ll N,M;

ll ans;

int main() {
    // insert code here...    return 0;
  //////
    // input from txt
    /*
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::ofstream out("output.txt");
    std::cout.rdbuf(out.rdbuf());
   ///////
     */
    
    cin >> N >> M;
    
    if(N<M){
        cout << 0 << endl;
        return 0;
    }
    
    ll e = 1;
    ll C = 1;
    for(int i=0;i<M;i++){
        ans = (ans+e*C*mod_pow(M-i,N)+MOD)%MOD;
        e *= -1;
        C = (C*(M-i)%MOD)*mod_inv(i+1)%MOD;
    }
    
    cout << ans << endl;
    return 0;
}
0