結果

問題 No.1140 EXPotentiaLLL!
ユーザー ApassApass
提出日時 2020-07-31 23:04:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 4,776 ms
コンパイル使用メモリ 75,580 KB
実行使用メモリ 59,552 KB
最終ジャッジ日時 2023-09-21 02:06:40
合計ジャッジ時間 16,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,853 ms
59,084 KB
testcase_01 AC 739 ms
59,204 KB
testcase_02 AC 1,850 ms
59,056 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1,483 ms
59,132 KB
testcase_08 AC 45 ms
49,392 KB
testcase_09 AC 46 ms
49,476 KB
testcase_10 AC 46 ms
49,376 KB
testcase_11 WA -
testcase_12 AC 44 ms
49,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) return false;
        }
        return true;
    }
}
0