結果

問題 No.502 階乗を計算するだけ
ユーザー vwxyz
提出日時 2022-05-01 23:31:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 700 bytes
コンパイル時間 3,569 ms
コンパイル使用メモリ 266,176 KB
実行使用メモリ 10,144 KB
最終ジャッジ日時 2024-07-01 00:57:39
合計ジャッジ時間 8,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33 TLE * 2 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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


long long int pow(long long int x,long long int n,long long int mod){
    if(n==0){
        return 1LL;
    }
    if(n%2==0){
        long long int p=pow(x,n/2,mod);
        return p*p%mod;
    }
    else{
        long long int p=pow(x,n/2,mod);
        p*=p;
        p%=mod;
        p*=x;
        return p%mod;
    }
}


int main(){
	long long mod=1000000007;
	long long ans;
	int N;cin>>N;
	if(N>=mod){
		ans=0;
	}
	else if(N<=mod/2){
		ans=1;
		for(int n=1;n<N+1;n++){
			ans*=n;
			ans%=mod;
		}
	}
	else{
		ans=mod-1;
		for(int n=N+1;n<mod;n++){
			ans*=n;
			ans%=mod;
		}
		ans=pow(ans,mod-2,mod);
	}
	cout<<ans<<endl;
}

0