結果
問題 |
No.109 N! mod M
|
ユーザー |
![]() |
提出日時 | 2014-12-21 23:39:01 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 557 bytes |
コンパイル時間 | 1,764 ms |
コンパイル使用メモリ | 74,100 KB |
実行使用メモリ | 54,568 KB |
最終ジャッジ日時 | 2024-06-12 03:21:04 |
合計ジャッジ時間 | 3,789 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 7 |
ソースコード
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); } } } }