結果
問題 | No.2326 Factorial to the Power of Factorial to the... |
ユーザー |
|
提出日時 | 2023-05-28 14:04:09 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 715 bytes |
コンパイル時間 | 4,701 ms |
コンパイル使用メモリ | 74,744 KB |
実行使用メモリ | 41,420 KB |
最終ジャッジ日時 | 2024-12-26 23:13:05 |
合計ジャッジ時間 | 9,500 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 WA * 9 |
ソースコード
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();int numP = 0;for(int i = 1; i <= N; i++){int n = i;while(n % P == 0){numP++;n /= P;}}int nM = 1;for(int i = 1; i <= N; i++){nM *= i;nM %= MOD;}char[] S = Integer.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);}}