結果
問題 | No.109 N! mod M |
ユーザー | ぴろず |
提出日時 | 2014-12-21 23:39:01 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 557 bytes |
コンパイル時間 | 3,020 ms |
コンパイル使用メモリ | 71,460 KB |
実行使用メモリ | 58,288 KB |
最終ジャッジ日時 | 2023-09-02 21:02:30 |
合計ジャッジ時間 | 5,423 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 149 ms
55,616 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 155 ms
55,888 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
ソースコード
package no109; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++) { int n = sc.nextInt(); int m = sc.nextInt(); if (n >= m) { System.out.println(0); }else if (n >= 100000) { long ans = m - 1; for(int x=m;x<=n;x++) { ans = (ans * x) % m; } System.out.println(ans); }else{ long ans = 1; for(int x=1;x<=n;x++) { ans = (ans * x) % m; } System.out.println(ans); } } } }