結果

問題 No.575 n! / m / m / m...
ユーザー 37zigen37zigen
提出日時 2017-10-07 04:25:34
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,677 bytes
コンパイル時間 2,596 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 43,036 KB
最終ジャッジ日時 2024-04-28 12:14:29
合計ジャッジ時間 8,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
42,776 KB
testcase_01 AC 166 ms
42,660 KB
testcase_02 AC 160 ms
42,900 KB
testcase_03 AC 151 ms
42,700 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 144 ms
42,596 KB
testcase_07 AC 147 ms
42,420 KB
testcase_08 AC 149 ms
42,804 KB
testcase_09 AC 142 ms
42,840 KB
testcase_10 AC 141 ms
42,348 KB
testcase_11 AC 160 ms
42,828 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 149 ms
42,896 KB
testcase_24 WA -
testcase_25 AC 140 ms
42,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		double n = sc.nextDouble();
		double m = sc.nextDouble();
		if (n < 100) {
			double ret = 1;
			for (int i = 2; i <= n; ++i) {
				int mul = i;
				while (mul % m == 0)
					mul /= m;
				ret *= mul;
			}
			int cnt = 0;
			while (ret >= 10) {
				++cnt;
				ret /= 10;
			}
			System.out.println(ret + "e" + cnt);
			return;
		}
		long c = 0;
		for (int i = 1; i < 1000; ++i)
			c += n / Math.pow(m, i);
		++n;
		long d = (long) (n * Math.log10((n + 1 / (12 * n - 1 / (10 * n))) / Math.E)
				+ (Math.log10(2 * Math.PI) - Math.log10(n)) * 0.5 - c * Math.log10(m));
		double p = fac(n);
		for (int i = 0; i < c; ++i) {
			p /= m;
			p = regulate(p);
		}
		System.out.println(p + "e" + d);
	}

	double fac(double n) {
		if (n < 1e8) {
			double ret = 1;
			for (int i = 1; i <= n; ++i) {
				ret *= i;
				ret = regulate(ret);
			}
			return ret;
		}
		double ret = Math.sqrt(2 * Math.PI) * pow(n / Math.E, (long) n) / Math.sqrt(n)
				* (1 + 1 / (12 * n) + 1 / (288 * n * n) - 139 / (51840 * n * n * n));
		ret = regulate(ret);
		return ret;
	}

	double regulate(double a) {
		while (a >= 10)
			a /= 10;
		while (a < 1)
			a *= 10;
		return a;
	}

	double pow(double a, long n) {
		double ret = 1;
		for (; n > 0; n >>= 1, a *= a) {
			while (a >= 10)
				a /= 10;
			if (n % 2 == 1) {
				ret *= a;
				while (ret >= 10)
					ret /= 10;
			}
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
0