結果

問題 No.1140 EXPotentiaLLL!
ユーザー ApassApass
提出日時 2020-07-31 22:59:20
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,658 bytes
コンパイル時間 4,247 ms
コンパイル使用メモリ 75,368 KB
実行使用メモリ 63,076 KB
最終ジャッジ日時 2023-09-21 01:55:05
合計ジャッジ時間 11,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 699 ms
62,384 KB
testcase_01 RE -
testcase_02 AC 699 ms
63,076 KB
testcase_03 AC 682 ms
62,792 KB
testcase_04 AC 620 ms
62,792 KB
testcase_05 AC 742 ms
63,048 KB
testcase_06 AC 720 ms
62,788 KB
testcase_07 WA -
testcase_08 AC 87 ms
55,060 KB
testcase_09 AC 85 ms
55,304 KB
testcase_10 AC 88 ms
54,940 KB
testcase_11 WA -
testcase_12 AC 86 ms
55,096 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();
    }

    static boolean[] INITIAL_PRIMES = initialPrimes();

    private static long solve() throws IOException {
        long A = readLong();
        int P = readInt();
        if (!INITIAL_PRIMES[P]) return -1;

        if (A % P == 0) return 0;
        else return 1;
    }

    private static boolean[] initialPrimes() {
        boolean[] isPrime = new boolean[5000000];
        for (int i = 3; i < 5000000; i += 2) {
            isPrime[i] = true;
        }
        for (int p = 3, squareRoot = (int) Math.sqrt(5000000); p <= squareRoot; p += 2) {
            if (isPrime[p]) {
                for (int j = p * p; j < 5000000; j += p)
                    isPrime[j] = false;
            }
        }
        return isPrime;
    }
}
0