結果
問題 | No.1140 EXPotentiaLLL! |
ユーザー | Apass |
提出日時 | 2020-07-31 23:07:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,848 ms / 2,000 ms |
コード長 | 1,478 bytes |
コンパイル時間 | 4,267 ms |
コンパイル使用メモリ | 74,592 KB |
実行使用メモリ | 59,920 KB |
最終ジャッジ日時 | 2023-09-21 02:14:17 |
合計ジャッジ時間 | 17,049 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,848 ms
59,112 KB |
testcase_01 | AC | 740 ms
59,388 KB |
testcase_02 | AC | 1,803 ms
58,920 KB |
testcase_03 | AC | 742 ms
59,500 KB |
testcase_04 | AC | 633 ms
59,920 KB |
testcase_05 | AC | 783 ms
57,276 KB |
testcase_06 | AC | 777 ms
58,436 KB |
testcase_07 | AC | 1,489 ms
59,184 KB |
testcase_08 | AC | 44 ms
49,616 KB |
testcase_09 | AC | 43 ms
49,316 KB |
testcase_10 | AC | 45 ms
49,408 KB |
testcase_11 | AC | 47 ms
49,468 KB |
testcase_12 | AC | 45 ms
49,460 KB |
ソースコード
import java.io.*; import java.util.HashSet; import java.util.StringTokenizer; public class EXPotentiaLLL { private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static StringTokenizer st; private static int readInt() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } private static Long readLong() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } public static void main(String[] args) throws IOException { int T = readInt(); while (T-- > 0) pw.println(solve()); pw.close(); } private static int solve() throws IOException { long A = readLong(); int P = readInt(); if (isPrime(P)) return A %P == 0 ? 0 : 1; else return -1; } static boolean isPrime(int n) { if (n < 2) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; int sqrtN = (int) Math.sqrt(n); for (int i = 6; i <= sqrtN + 1; i += 6) { if (n % (i - 1) == 0 || n % (i + 1) == 0) return false; } return true; } }