結果

問題 No.1140 EXPotentiaLLL!
ユーザー 37zigen37zigen
提出日時 2020-07-31 22:03:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 2,954 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 74,284 KB
実行使用メモリ 62,652 KB
最終ジャッジ日時 2023-09-20 23:25:14
合計ジャッジ時間 8,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 402 ms
61,336 KB
testcase_01 AC 479 ms
61,560 KB
testcase_02 AC 402 ms
59,428 KB
testcase_03 AC 438 ms
61,432 KB
testcase_04 AC 447 ms
62,048 KB
testcase_05 AC 515 ms
62,016 KB
testcase_06 AC 509 ms
62,652 KB
testcase_07 AC 455 ms
61,704 KB
testcase_08 AC 119 ms
55,632 KB
testcase_09 AC 118 ms
55,564 KB
testcase_10 AC 121 ms
55,984 KB
testcase_11 AC 121 ms
55,624 KB
testcase_12 AC 117 ms
55,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int T=sc.nextInt();
		PrintWriter pw=new PrintWriter(System.out);
		boolean[] isPrime=new boolean[5000001];
		Arrays.fill(isPrime, true);
		isPrime[0]=isPrime[1]=false;
		for (int i=2;i<isPrime.length;++i) {
			if (!isPrime[i]) continue;
			for (int j=2*i;j<isPrime.length;j+=i) {
				isPrime[j]=false;
			}
		}
		while (T-->0) {
			long A=sc.nextLong();
			int P=sc.nextInt();
			if (isPrime[P]) {
				if (A%P==0) {
					pw.println(0);
				} else {
					pw.println(1);					
				}
			} else {
				pw.println(-1);
			}
		}
		pw.flush();
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
	
	class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        if (!hasNext()) throw new NoSuchElementException();
	        long n = 0;
	        boolean minus = false;
	        int b = readByte();
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        if (b < '0' || '9' < b) {
	            throw new NumberFormatException();
	        }
	        while(true){
	            if ('0' <= b && b <= '9') {
	                n *= 10;
	                n += b - '0';
	            }else if(b == -1 || !isPrintableChar(b)){
	                return minus ? -n : n;
	            }else{
	                throw new NumberFormatException();
	            }
	            b = readByte();
	        }
	    }
	    public int nextInt() {
	    	return (int)nextLong();
	    }
	}
}

0