結果
| 問題 |
No.575 n! / m / m / m...
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-13 12:46:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,782 bytes |
| コンパイル時間 | 1,926 ms |
| コンパイル使用メモリ | 166,692 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 11:21:34 |
| 合計ジャッジ時間 | 4,248 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 13 |
ソースコード
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
/*
Legendre's formula
nを自然数、pを素数とするとき
p^x | n!
を満たす最大の非負整数xを返す。
時間
O(log(n))
参考
https://en.wikipedia.org/wiki/Legendre%27s_formula
*/
long long LegendreFormula(long long n, long long p) {
long long res = 0, d = p, a;
while ((a = n / d) != 0) {
res += a;
d *= p;
}
return res;
}
/*
スターリングの近似
log(n!)の近似
https://ja.wikipedia.org/wiki/%E3%82%B9%E3%82%BF%E3%83%BC%E3%83%AA%E3%83%B3%E3%82%B0%E3%81%AE%E8%BF%91%E4%BC%BC
*/
double stirlingsApproximation(long long n) {
return n * log(n) - n + 0.5*log(2 * M_PI*n) + 1.0/(12*n);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll n, m, p;
cin >> n >> m;
double x = stirlingsApproximation(n);
auto f = [&](ll p) {
x -= LegendreFormula(n, p)*log(p);
};
for (p = 2; p*p <= m; ++p) {
if (m%p == 0) {
while (m%p == 0)m /= p;
f(p);
}
}
if (m != 1) {
f(m);
}
double x10 = x / log(10.0);
ll pw = (ll)x10;
x10 -= pw;
x = x10 * log(10);
cout << exp(x) << 'e' << pw << endl;
}