結果

問題 No.575 n! / m / m / m...
ユーザー 37zigen37zigen
提出日時 2017-10-07 05:14:39
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 3,076 ms
コンパイル使用メモリ 85,112 KB
実行使用メモリ 43,316 KB
最終ジャッジ日時 2024-04-28 12:19:07
合計ジャッジ時間 9,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
42,444 KB
testcase_01 AC 171 ms
42,732 KB
testcase_02 AC 182 ms
42,940 KB
testcase_03 AC 170 ms
42,804 KB
testcase_04 AC 185 ms
42,800 KB
testcase_05 AC 177 ms
42,572 KB
testcase_06 AC 187 ms
42,880 KB
testcase_07 AC 183 ms
42,604 KB
testcase_08 AC 184 ms
43,016 KB
testcase_09 AC 185 ms
43,128 KB
testcase_10 AC 176 ms
42,728 KB
testcase_11 AC 184 ms
42,728 KB
testcase_12 AC 179 ms
43,236 KB
testcase_13 WA -
testcase_14 AC 178 ms
42,836 KB
testcase_15 WA -
testcase_16 AC 173 ms
42,632 KB
testcase_17 WA -
testcase_18 AC 156 ms
42,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 196 ms
42,856 KB
testcase_24 WA -
testcase_25 AC 180 ms
42,556 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(ori / i);
			}
		}
		if (ret.size() == 0)
			ret.add(ori);
		return ret;
	}

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

}
0