結果

問題 No.502 階乗を計算するだけ
ユーザー Kmcode1
提出日時 2017-04-07 23:27:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 790 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 167,168 KB
実行使用メモリ 166,556 KB
最終ジャッジ日時 2024-07-16 03:06:25
合計ジャッジ時間 4,693 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 TLE * 1 -- * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         scanf("%lld", &n);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

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




#define MOD 1000000007

map<pair<long long int,long long int>, long long int> mp;

long long int recfact(long long int start, long long int n) {
	long long int i;
	if (mp.count(make_pair(start, n) )){
		return mp[make_pair(start, n)];
	}
	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;
	mp[make_pair(start,n)]=(recfact(start, i) * recfact(start + i, n - i))%MOD;
	return mp[{start, n}];
}
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