結果

問題 No.2725 Coprime Game 2
ユーザー ks2mks2m
提出日時 2024-04-12 22:32:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 75,164 KB
実行使用メモリ 63,168 KB
最終ジャッジ日時 2024-04-12 22:32:25
合計ジャッジ時間 4,728 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,308 KB
testcase_01 AC 53 ms
50,528 KB
testcase_02 AC 55 ms
50,376 KB
testcase_03 AC 266 ms
56,540 KB
testcase_04 AC 304 ms
63,168 KB
testcase_05 AC 268 ms
56,504 KB
testcase_06 AC 263 ms
55,960 KB
testcase_07 AC 234 ms
55,816 KB
testcase_08 AC 289 ms
56,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int z = 0; z < t; z++) {
			long n = Long.parseLong(br.readLine());
			if (n == 2) {
				pw.println("P");
				continue;
			}

			long goal = 0;
			for (int i = 2; i < n; i++) {
				if (n % i != 0) {
					goal = i;
					break;
				}
			}
			long g = gcd(goal, n);
			if (g == 1) {
				pw.println("K");
			} else {
				pw.println("P");
			}
		}
		pw.flush();
		br.close();
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}
0