結果

問題 No.575 n! / m / m / m...
ユーザー 37zigen37zigen
提出日時 2017-10-07 05:19:36
言語 Java21
(openjdk 21)
結果
WA  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,356 bytes
コンパイル時間 2,803 ms
コンパイル使用メモリ 88,928 KB
実行使用メモリ 43,108 KB
最終ジャッジ日時 2024-05-04 00:02:49
合計ジャッジ時間 9,302 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
42,976 KB
testcase_01 AC 187 ms
42,836 KB
testcase_02 AC 183 ms
42,516 KB
testcase_03 AC 182 ms
42,536 KB
testcase_04 AC 185 ms
42,812 KB
testcase_05 AC 181 ms
42,908 KB
testcase_06 AC 179 ms
42,836 KB
testcase_07 AC 179 ms
42,856 KB
testcase_08 AC 181 ms
43,028 KB
testcase_09 AC 183 ms
42,824 KB
testcase_10 AC 181 ms
42,796 KB
testcase_11 AC 169 ms
42,732 KB
testcase_12 AC 180 ms
42,896 KB
testcase_13 AC 180 ms
42,824 KB
testcase_14 AC 178 ms
42,952 KB
testcase_15 AC 182 ms
42,832 KB
testcase_16 AC 177 ms
43,004 KB
testcase_17 AC 166 ms
42,944 KB
testcase_18 AC 178 ms
42,708 KB
testcase_19 AC 182 ms
42,936 KB
testcase_20 AC 182 ms
42,780 KB
testcase_21 AC 183 ms
42,928 KB
testcase_22 WA -
testcase_23 AC 210 ms
42,860 KB
testcase_24 WA -
testcase_25 AC 208 ms
42,704 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 = Integer.MAX_VALUE;
		ArrayList<Long> lis = plis((long) m);
		for (long p : lis) {
			long tmp = 0;
			for (int i = 1; i < 1000; ++i)
				tmp += n / Math.pow(p, i);
			c = Math.min(c, tmp);
		}
		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> plis(long n) {
		long ori = n;
		ArrayList<Long> ret = new ArrayList<>();
		for (long i = 2; i * i <= n; ++i) {
			if (n % i == 0) {
				while (n % i == 0) {
					n /= i;
				}
				ret.add(i);
			}
		}
		ret.add(n);
		return ret;
	}

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

}
0