結果

問題 No.726 Tree Game
ユーザー YamaKasaYamaKasa
提出日時 2018-08-24 21:59:47
言語 Java19
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 2,914 ms
コンパイル使用メモリ 73,772 KB
実行使用メモリ 56,076 KB
最終ジャッジ日時 2023-09-05 11:42:29
合計ジャッジ時間 6,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,744 KB
testcase_01 AC 126 ms
55,532 KB
testcase_02 AC 126 ms
55,348 KB
testcase_03 AC 126 ms
55,092 KB
testcase_04 AC 124 ms
55,548 KB
testcase_05 AC 124 ms
55,676 KB
testcase_06 AC 124 ms
55,780 KB
testcase_07 AC 124 ms
55,480 KB
testcase_08 AC 124 ms
55,252 KB
testcase_09 AC 125 ms
55,328 KB
testcase_10 AC 123 ms
55,820 KB
testcase_11 AC 124 ms
55,508 KB
testcase_12 AC 125 ms
55,952 KB
testcase_13 AC 124 ms
55,104 KB
testcase_14 AC 125 ms
55,788 KB
testcase_15 AC 123 ms
55,984 KB
testcase_16 AC 125 ms
55,620 KB
testcase_17 AC 125 ms
55,580 KB
testcase_18 AC 125 ms
55,272 KB
testcase_19 AC 126 ms
56,076 KB
testcase_20 AC 125 ms
55,956 KB
testcase_21 AC 124 ms
56,048 KB
testcase_22 AC 127 ms
55,960 KB
testcase_23 AC 125 ms
55,616 KB
testcase_24 AC 125 ms
55,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long Y = scan.nextLong();
		long X = scan.nextLong();
		scan.close();
		long pX = X + 1;
		long pY = Y + 1;
		while(!isPrime(pX)) {
			pX ++;
		}
		while(!isPrime(pY)) {
			pY ++;
		}
		long k = pX - X + pY - Y - 2;
		if(isPrime(Y) && isPrime(X)) {
			System.out.println("Second");
			System.exit(0);
		}else if((isPrime(Y) && isPrime(Y + 1)) || isPrime(X) && isPrime(X + 1)){
			System.out.println("Second");
			System.exit(0);
		}
		if(k % 2 == 0) {
			System.out.println("Second");
		}else {
			System.out.println("First");
		}

	}
	public static boolean isPrime(long n) {
		if(n < 2) return false;
		if(n == 2) return true;
		if(n % 2 == 0) return false;
        for(long i = 3; i <= (long)Math.sqrt(n); i += 2){
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0