結果

問題 No.1140 EXPotentiaLLL!
ユーザー ApassApass
提出日時 2020-07-31 22:58:09
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,657 bytes
コンパイル時間 5,562 ms
コンパイル使用メモリ 75,440 KB
実行使用メモリ 64,864 KB
最終ジャッジ日時 2023-09-21 01:51:41
合計ジャッジ時間 11,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
権限があれば一括ダウンロードができます

ソースコード

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