結果

問題 No.502 階乗を計算するだけ
コンテスト
ユーザー Kmcode1
提出日時 2017-04-07 23:25:34
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 616 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,452 ms
コンパイル使用メモリ 173,728 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2026-03-30 17:56:05
合計ジャッジ時間 6,319 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 TLE * 2 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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




#define MOD 1000000007

long long int recfact(long long int start, long long int n) {
	long long int i;
	if (n <= 16) {
		long long int r = start;
		for (i = start + 1; i < start + n; i++) r *= i,r%=MOD;
		return r%MOD;
	}
	i = n / 2;
	return (recfact(start, i) * recfact(start + i, n - i))%MOD;
}
long long int factorial(long  n) { return recfact(1, n); }

int main(){
	long long int n;
	scanf("%lld", &n);
	if (n >= MOD){
		puts("0");
		return 0;
	}
	long long int c = factorial(n);
	printf("%lld\n", c);
	return 0;
}
0