結果

問題 No.889 素数!
ユーザー ks2mks2m
提出日時 2019-09-20 22:42:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 84,268 KB
実行使用メモリ 56,408 KB
最終ジャッジ日時 2023-10-12 20:22:25
合計ジャッジ時間 13,336 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,636 KB
testcase_01 AC 126 ms
56,056 KB
testcase_02 AC 122 ms
55,952 KB
testcase_03 AC 123 ms
56,120 KB
testcase_04 AC 123 ms
55,944 KB
testcase_05 AC 123 ms
55,956 KB
testcase_06 AC 124 ms
56,264 KB
testcase_07 AC 120 ms
56,100 KB
testcase_08 AC 121 ms
55,436 KB
testcase_09 AC 125 ms
56,244 KB
testcase_10 AC 122 ms
55,932 KB
testcase_11 AC 123 ms
53,936 KB
testcase_12 AC 123 ms
56,084 KB
testcase_13 AC 128 ms
55,852 KB
testcase_14 AC 124 ms
56,272 KB
testcase_15 AC 126 ms
55,884 KB
testcase_16 AC 121 ms
55,932 KB
testcase_17 AC 127 ms
55,912 KB
testcase_18 AC 124 ms
55,772 KB
testcase_19 AC 127 ms
55,648 KB
testcase_20 AC 121 ms
55,784 KB
testcase_21 AC 127 ms
56,068 KB
testcase_22 AC 126 ms
56,124 KB
testcase_23 AC 127 ms
55,872 KB
testcase_24 AC 126 ms
55,708 KB
testcase_25 AC 127 ms
55,804 KB
testcase_26 AC 122 ms
56,096 KB
testcase_27 AC 128 ms
55,916 KB
testcase_28 AC 121 ms
55,720 KB
testcase_29 AC 127 ms
56,064 KB
testcase_30 AC 122 ms
56,196 KB
testcase_31 AC 126 ms
55,776 KB
testcase_32 AC 121 ms
55,728 KB
testcase_33 AC 126 ms
55,916 KB
testcase_34 AC 127 ms
55,664 KB
testcase_35 AC 128 ms
55,892 KB
testcase_36 AC 130 ms
55,776 KB
testcase_37 AC 125 ms
55,936 KB
testcase_38 AC 127 ms
55,600 KB
testcase_39 AC 130 ms
56,164 KB
testcase_40 AC 128 ms
56,100 KB
testcase_41 AC 121 ms
55,936 KB
testcase_42 AC 125 ms
55,496 KB
testcase_43 AC 121 ms
56,132 KB
testcase_44 AC 127 ms
56,340 KB
testcase_45 AC 127 ms
55,884 KB
testcase_46 AC 128 ms
55,968 KB
testcase_47 AC 125 ms
56,148 KB
testcase_48 AC 126 ms
56,308 KB
testcase_49 AC 122 ms
55,480 KB
testcase_50 AC 127 ms
56,280 KB
testcase_51 AC 126 ms
55,920 KB
testcase_52 AC 129 ms
55,972 KB
testcase_53 AC 125 ms
55,808 KB
testcase_54 AC 128 ms
56,068 KB
testcase_55 AC 127 ms
55,812 KB
testcase_56 AC 127 ms
55,772 KB
testcase_57 AC 126 ms
54,592 KB
testcase_58 AC 125 ms
55,516 KB
testcase_59 AC 122 ms
55,872 KB
testcase_60 AC 128 ms
56,408 KB
testcase_61 AC 125 ms
56,196 KB
testcase_62 AC 131 ms
55,796 KB
testcase_63 AC 129 ms
56,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		if (n < 2) {
			System.out.println(n);
			return;
		}

		if (isSosuu(n)) {
			System.out.println("Sosu!");
			return;
		}

		int n2 = (int) Math.sqrt(n);
		if (n2 * n2 == n) {
			System.out.println("Heihosu!");
			return;
		}

		if (n == 8 || n == 27 || n == 64) {
			System.out.println("Ripposu!");
			return;
		}

		List<Long> list = new ArrayList<>();
		long end = (long) Math.sqrt(n);
		for (int i = 1; i <= end; i++) {
			if (n % i == 0) {
				list.add((long) i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		if (list.stream().mapToLong(a -> a).sum() == n * 2) {
			System.out.println("Kanzensu!");
			return;
		}

		System.out.println(n);
	}

	static boolean isSosuu(long n) {
		for (int i = 2; i < n; i++) {
			if (n % i == 0) {
				return false;
			}
		}
		return true;
	}
}
0