結果

問題 No.2326 Factorial to the Power of Factorial to the...
ユーザー AckvyAckvy
提出日時 2023-05-28 14:09:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 770 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 71,000 KB
実行使用メモリ 56,068 KB
最終ジャッジ日時 2023-08-27 09:07:36
合計ジャッジ時間 7,281 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,052 KB
testcase_01 WA -
testcase_02 AC 124 ms
55,884 KB
testcase_03 AC 123 ms
55,704 KB
testcase_04 WA -
testcase_05 AC 122 ms
55,756 KB
testcase_06 AC 125 ms
55,920 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 123 ms
55,820 KB
testcase_11 AC 122 ms
55,692 KB
testcase_12 AC 131 ms
55,988 KB
testcase_13 WA -
testcase_14 AC 123 ms
55,848 KB
testcase_15 WA -
testcase_16 AC 124 ms
55,548 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
56,028 KB
testcase_20 AC 122 ms
55,876 KB
testcase_21 AC 124 ms
53,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main{
	static final int MOD = 1000000007;

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int P = sc.nextInt();

		if(N < P){
			System.out.println(0);
			return;
		}

		Long numP = 0l;
		for(int i = 1; i <= N; i++){
			int n = i;
			while(n % P == 0){
				numP++;
				n /= P;
			}
		}

		long nM = 1;
		for(int i = 1; i <= N; i++){
			nM *= i;
			nM %= MOD;
		}

		char[] S = Long.toBinaryString(nM).toCharArray();
		long binM = nM;
		long ans = 1;

		for(int i = S.length-1; i >= 0; i--){
//			System.out.print(S[i]);
			if(S[i] == '1'){
				ans *= binM;
				ans %= MOD;
			}
			binM *= binM;
			binM %= MOD;
		}

		ans *= numP;
		ans %= MOD;

		System.out.println(ans);
	}
}
0