結果

問題 No.502 階乗を計算するだけ
ユーザー kmjpkmjp
提出日時 2017-04-07 22:40:24
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 160,652 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-07-16 02:26:01
合計ジャッジ時間 4,843 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 11 TLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N;
ll mo=1000000007;

bool isprime(ll v) {
	for(ll i=2;i*i<=v;i++) if(v%i==0) return false;
	return (v!=1);
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	if(N>=mo) {
		cout<<0<<endl;
		return;
	}
	else if(N<100) {
		ll ret=1;
		for(i=1;i<=N;i++) ret=ret*i%mo;
		cout<<ret<<endl;
	}
	else {
		ll T=N;
		while(isprime(T)==0) T--;
		ll ret=T-1;
		for(i=1;i<=N;i++) ret=ret*i%mo;
		cout<<ret<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0