結果

問題 No.575 n! / m / m / m...
ユーザー chocorusk
提出日時 2019-09-03 12:03:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 104,604 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 15:57:07
合計ジャッジ時間 2,101 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const double PI=acos(-1.0);
int main()
{
	ll n, m; cin>>n>>m;
	vector<P> v;
	ll m1=m;
	for(ll i=2; i*i<=m1; i++){
		if(m1%i==0){
			ll e=0;
			while(m1%i==0){
				e++;
				m1/=i;
			}
			v.push_back({i, e});
		}
	}
	if(m1>1) v.push_back({m1, 1});
	ll k=1e12;
	for(auto q:v){
		ll p=q.first, e=q.second;
		ll c=0, n1=n/p;
		while(n1){
			c+=n1;
			n1/=p;
		}
		k=min(k, c/e);
	}
	double ans=-k*log10((double)m);
	if(n>1e6) ans+=1/log(10.0)*(n*log((double)n)-n+0.5*log(2*PI*n));
	else{
		for(int i=1; i<=n; i++) ans+=log10((double)i);
	}
	ll d=(ll)ans;
	double p=pow(10.0, ans-d);
	printf("%.3lfe%lld", p, d);
	return 0;
}
0