結果

問題 No.391 CODING WAR
ユーザー confconf
提出日時 2016-07-09 13:42:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,513 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 66,040 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-21 10:42:39
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,448 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int p=1000000007;

int extgcd(int a, int b, int&x, int&y){
    int d=a;
    if(b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }else{
        x=1;y=0;
    }
    return d;
}

int mod_inverse(int a, int m){
    int x, y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int fact(int n, int p){
    static int F[100001];
    if(F[n]) return F[n];
    long long int res=1;
    while(n){
        res*=n;
        if(res>p)res%=p;
        if(res==0)return 0;
        n--;
    }
    return F[n]=(int)res;
}

int mod_fact(int n,int p,int &e){
    e=0;
    if(n==0)return 1;
    long long int res=mod_fact(n/p,p,e);
    e+=n/p;
    if(n/p%2!=0) return res*(p-fact(n%p,p))%p;
    return (int)(res*fact(n%p,p)%p);
}

int mod_comb(int n, int k,int p){
    if(n<0||k<0||n<k)return 0;
    int e1,e2,e3;
    long long int a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3)return 0;
    return (a1*mod_inverse(a2*a3%p,p))%p;
}

int mod_pow(long long int a, long long int e, int p){
    long long int res = 1;
    for(;e>0;e/=2){
        if(e%2)res=(res*a)%p;
        a=(a*a)%p;
    }
    return (int)res;
}

int main(){
    long long int N,M;
    cin>>N>>M;
    long long int ans=0;
    for(int i=1;i<=M;i++){
        if((M-i)%2){
            ans=(p+ans-((long long int)mod_comb(M,i,p)*mod_pow(i,N,p))%p)%p;
        }else{
            ans=(ans+((long long int)mod_comb(M,i,p)*mod_pow(i,N,p))%p)%p;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0