結果

問題 No.500 階乗電卓
ユーザー vjudge1
提出日時 2025-06-20 16:58:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 195,116 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 16:58:27
合計ジャッジ時間 2,953 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
??????
??????
??????
??????
D P ????
??????
??????
??????
??????
??? l l?
??????
??????
?? OI ??
??????
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define eps 1e-9
//#define ENF 1e13
const int N=1e1;
const int mod=1e9+7;
inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
   return x*f;
}
void write(int x)
{
   if(x<0)putchar('-'),x=-x;
   if(x<10)putchar(x+'0');
   else write(x/10),putchar(x%10+'0');
}
string s;
signed main(){
//	freopen("factorial.in","r",stdin);
//	freopen("factorial.out","w",stdout);
	int n=read();
	int sum=n/5;
	if(n>=60){
		cout<<"000000000000";
		return 0;
	}
	
	int q=pow(10,12-sum);
	int Q=0;
	int y=1;
	for(int i=1;i<=n;i++){
		if(i%5==0){
			(y*=(i/5))%=q;
			continue;
		}
		if(i%2==0&&Q<sum){
			Q++;
			(y*=(i/2))%=q;
			continue;
		}
		(y*=i)%=q;
	}
	for(int i=1;i<=sum;i++)s+='0';
	while(y){
		s+=char(y%10+'0');
		y/=10;
	}
	if(n<15){
		reverse(s.begin(),s.end());
		cout<<s<<"\n";
		return 0;
	}
	while(s.size()<12){
		s+='0';
	}
	reverse(s.begin(),s.end());
	cout<<s<<"\n";
	
   return 0;
}
// ?????????????AC????
// ?????????????????????????
// ??????????????????
// ????????????????????????????????????
// ???????????????????????????????
// ????????????
// ????????????
// ????????????
// ????????????????????
// ????????????????????
// ????????????????????????????????
// ???????????????????????
// ???????????
// ?????????????
// ????Elysian_Realme???
// ????OIer???OIer??

0