結果

問題 No.575 n! / m / m / m...
ユーザー 37zigen37zigen
提出日時 2017-10-07 05:52:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,608 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 42,988 KB
最終ジャッジ日時 2024-04-28 12:19:28
合計ジャッジ時間 7,631 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
42,684 KB
testcase_01 AC 154 ms
42,344 KB
testcase_02 AC 166 ms
42,896 KB
testcase_03 AC 164 ms
42,908 KB
testcase_04 AC 152 ms
42,552 KB
testcase_05 AC 149 ms
42,320 KB
testcase_06 AC 132 ms
42,656 KB
testcase_07 AC 163 ms
42,988 KB
testcase_08 AC 134 ms
42,920 KB
testcase_09 AC 145 ms
42,776 KB
testcase_10 AC 159 ms
42,596 KB
testcase_11 AC 159 ms
42,776 KB
testcase_12 AC 163 ms
42,728 KB
testcase_13 AC 161 ms
42,600 KB
testcase_14 AC 160 ms
42,392 KB
testcase_15 AC 151 ms
42,308 KB
testcase_16 AC 160 ms
42,988 KB
testcase_17 AC 168 ms
42,888 KB
testcase_18 AC 153 ms
42,820 KB
testcase_19 AC 155 ms
42,720 KB
testcase_20 AC 160 ms
42,024 KB
testcase_21 AC 171 ms
42,780 KB
testcase_22 AC 150 ms
42,608 KB
testcase_23 AC 176 ms
42,840 KB
testcase_24 AC 157 ms
42,704 KB
testcase_25 AC 183 ms
42,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
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();
		long c = Long.MAX_VALUE;
		ArrayList<long[]> lis = flis((long) (m + 1e-9));
		for (long[] f : lis) {
			long tmp = 0;
			long n_ = (long) (n + 1e-9);
			while (n_ > 1) {
				tmp += n_ / f[0];
				n_ /= f[0];
			}
			c = Math.min(c, tmp / f[1]);
		}
		if (n < 170) {
			double ret = 1;
			for (int i = 2; i <= n; ++i) {
				ret *= i;
			}
			while (ret % m == 0)
				ret /= m;
			int cnt = 0;
			while (ret >= 10) {
				++cnt;
				ret /= 10;
			}
			System.out.println(ret + "e" + cnt);
			return;
		}
		++n;
		double v = (Math.log10(Math.sqrt(2 * Math.PI)) + n * Math.log10(n / Math.E) - 0.5 * Math.log10(n)
				+ Math.log10(1 + 1 / (12 * n) + 1 / (288 * n * n) - 139 / (51840 * n * n * n))) - c * Math.log10(m);
		System.out.println(Math.pow(10, v - (long) v) + "e" + (long) v);
	}

	ArrayList<long[]> flis(long n) {
		ArrayList<long[]> ret = new ArrayList<>();
		for (long i = 2; i * i <= n; ++i) {
			if (n % i == 0) {
				int c = 0;
				while (n % i == 0) {
					n /= i;
					++c;
				}
				ret.add(new long[] { i, c });
			}
		}
		if (n > 1)
			ret.add(new long[] { n, 1 });
		return ret;
	}

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

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

}
0