結果

問題 No.889 素数!
ユーザー htensaihtensai
提出日時 2020-02-13 18:09:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,428 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 77,172 KB
実行使用メモリ 41,584 KB
最終ジャッジ日時 2024-04-15 23:17:10
合計ジャッジ時間 11,925 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
41,352 KB
testcase_01 AC 128 ms
41,236 KB
testcase_02 AC 114 ms
40,308 KB
testcase_03 AC 125 ms
41,368 KB
testcase_04 AC 125 ms
41,156 KB
testcase_05 AC 127 ms
41,396 KB
testcase_06 AC 118 ms
40,500 KB
testcase_07 AC 131 ms
41,336 KB
testcase_08 AC 125 ms
41,192 KB
testcase_09 AC 113 ms
40,032 KB
testcase_10 AC 127 ms
41,540 KB
testcase_11 AC 113 ms
40,000 KB
testcase_12 AC 114 ms
40,296 KB
testcase_13 AC 122 ms
41,048 KB
testcase_14 AC 119 ms
40,524 KB
testcase_15 AC 127 ms
41,104 KB
testcase_16 AC 114 ms
40,060 KB
testcase_17 AC 116 ms
39,880 KB
testcase_18 AC 123 ms
41,276 KB
testcase_19 AC 113 ms
40,236 KB
testcase_20 AC 129 ms
41,448 KB
testcase_21 AC 113 ms
40,292 KB
testcase_22 AC 134 ms
41,404 KB
testcase_23 AC 113 ms
40,016 KB
testcase_24 AC 116 ms
39,896 KB
testcase_25 AC 128 ms
41,368 KB
testcase_26 AC 138 ms
41,132 KB
testcase_27 AC 127 ms
41,228 KB
testcase_28 AC 114 ms
39,892 KB
testcase_29 AC 127 ms
40,948 KB
testcase_30 AC 130 ms
41,472 KB
testcase_31 AC 125 ms
40,972 KB
testcase_32 AC 127 ms
41,144 KB
testcase_33 AC 112 ms
40,264 KB
testcase_34 AC 109 ms
39,776 KB
testcase_35 AC 125 ms
41,008 KB
testcase_36 AC 114 ms
40,056 KB
testcase_37 AC 126 ms
41,252 KB
testcase_38 AC 133 ms
41,460 KB
testcase_39 AC 131 ms
41,584 KB
testcase_40 AC 128 ms
41,400 KB
testcase_41 AC 130 ms
40,956 KB
testcase_42 AC 128 ms
41,224 KB
testcase_43 AC 128 ms
41,056 KB
testcase_44 AC 127 ms
41,364 KB
testcase_45 AC 127 ms
41,196 KB
testcase_46 AC 126 ms
41,176 KB
testcase_47 AC 134 ms
41,496 KB
testcase_48 AC 130 ms
41,300 KB
testcase_49 AC 132 ms
41,096 KB
testcase_50 AC 130 ms
41,300 KB
testcase_51 AC 117 ms
40,224 KB
testcase_52 AC 129 ms
41,336 KB
testcase_53 AC 113 ms
39,892 KB
testcase_54 AC 126 ms
41,292 KB
testcase_55 AC 132 ms
41,276 KB
testcase_56 AC 126 ms
41,160 KB
testcase_57 AC 115 ms
40,180 KB
testcase_58 AC 126 ms
40,972 KB
testcase_59 AC 127 ms
41,532 KB
testcase_60 AC 116 ms
40,236 KB
testcase_61 AC 127 ms
41,004 KB
testcase_62 AC 136 ms
41,404 KB
testcase_63 AC 140 ms
41,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n <= 1) {
		    System.out.println(n);
		    return;
		}
		int ans = 0;
		if (isPrime(n)) {
		    ans += 1;
		}
		if (isDbl(n)) {
		    ans += 2;
		}
		if (isTr(n)) {
		    ans += 4;
		}
		if (isPerf(n)) {
		    ans += 8;
		}
		String str;
		if (ans == 1) {
		    str = "Sosu!";
		} else if (ans == 2) {
		    str = "Heihosu!";
		} else if (ans == 4) {
		    str = "Ripposu!";
		} else if (ans == 8) {
		    str = "Kanzensu!";
		} else {
		    str = String.valueOf(n);
		}
		System.out.println(str);
   }
   
   static boolean isPrime(int x) {
       for (int i = 2; i <= Math.sqrt(x); i++) {
           if (x % i == 0) {
               return false;
           }
       }
       return true;
   }
   
   static boolean isDbl(int x) {
       for (int i = 2; i * i <= x; i++) {
           if (i * i == x) {
               return true;
           }
       }
       return false;
   }
   
   static boolean isTr(int x) {
       for (int i = 2; i * i * i <= x; i++) {
           if (i * i * i == x) {
               return true;
           }
       }
       return false;
   }
   
   static boolean isPerf(int x) {
       int sum = 1;
       for (int i = 2; i < x; i++) {
           if (x % i == 0) {
               sum += i;
           }
       }
       return sum == x;
   }
}
0