結果

問題 No.391 CODING WAR
ユーザー hashiryohashiryo
提出日時 2018-04-25 14:59:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 59,736 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 05:27:11
合計ジャッジ時間 1,674 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 46 ms
4,380 KB
testcase_10 AC 47 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 40 ms
4,380 KB
testcase_16 AC 24 ms
4,380 KB
testcase_17 AC 28 ms
4,376 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 20 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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