結果

問題 No.575 n! / m / m / m...
ユーザー e869120e869120
提出日時 2018-06-10 12:23:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,125 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 78,504 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 02:36:39
合計ジャッジ時間 2,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 12 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 12 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

long double factorial(long long x) {
	if (x <= 10000) {
		long double ret = 0;
		for (int i = 1; i <= x; i++) ret += log10(1.0L*i);
		return ret;
	}
	long double ans = 1.0L*x*(log(1.0L*x) - 1) / log(10.0L);
	long double dig = log10(1.0L * x); dig /= 2;
	ans += dig + 0.399L;
	return ans;
}

long long n, m;

void calc(long double G) {
	long long T = (long long)(1.0L*G);
	G -= 1.0L*T;
	printf("%.10Lf", pow(10.0L, G));
	cout << "e" << T << endl;
}

int main() {
	cin >> n >> m;
	long double E = factorial(n);

	long long I = m;
	vector<pair<long long, long long>>F;
	for (long long i = 2; i*i <= m; i++) {
		long long cnt = 0;
		while (I%i == 0) { I /= i; cnt++; }
		if (cnt >= 1) F.push_back(make_pair(i, cnt));
	}
	if (I >= 2) F.push_back(make_pair(I, 1));

	long long minx = (1LL << 60);
	for (int i = 0; i < F.size(); i++) {
		long long J = n, sum = 0;
		while (J >= 1) {
			J /= F[i].first; sum += J;
		}
		minx = min(minx, sum / F[i].second);
	}

	long double T = log10(1.0L*m);
	E -= 1.0L*T*minx;

	calc(E);
	return 0;
}
0