結果

問題 No.889 素数!
ユーザー htensaihtensai
提出日時 2020-02-13 18:08:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 77,628 KB
実行使用メモリ 41,604 KB
最終ジャッジ日時 2024-04-15 23:16:51
合計ジャッジ時間 11,509 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,444 KB
testcase_01 AC 126 ms
41,604 KB
testcase_02 AC 117 ms
40,800 KB
testcase_03 WA -
testcase_04 AC 122 ms
41,208 KB
testcase_05 AC 124 ms
41,168 KB
testcase_06 AC 123 ms
41,012 KB
testcase_07 AC 112 ms
39,912 KB
testcase_08 AC 122 ms
41,592 KB
testcase_09 AC 114 ms
40,236 KB
testcase_10 AC 112 ms
40,364 KB
testcase_11 AC 126 ms
40,964 KB
testcase_12 AC 112 ms
40,120 KB
testcase_13 AC 111 ms
40,164 KB
testcase_14 AC 125 ms
41,268 KB
testcase_15 AC 111 ms
40,212 KB
testcase_16 AC 113 ms
40,032 KB
testcase_17 AC 122 ms
41,280 KB
testcase_18 AC 122 ms
41,228 KB
testcase_19 AC 111 ms
40,152 KB
testcase_20 AC 122 ms
41,212 KB
testcase_21 AC 124 ms
41,308 KB
testcase_22 AC 124 ms
41,116 KB
testcase_23 AC 121 ms
41,260 KB
testcase_24 AC 127 ms
41,352 KB
testcase_25 AC 119 ms
41,080 KB
testcase_26 AC 126 ms
41,292 KB
testcase_27 AC 126 ms
41,332 KB
testcase_28 AC 115 ms
40,220 KB
testcase_29 AC 127 ms
41,412 KB
testcase_30 AC 112 ms
40,220 KB
testcase_31 AC 117 ms
41,036 KB
testcase_32 AC 126 ms
41,228 KB
testcase_33 AC 112 ms
40,116 KB
testcase_34 AC 124 ms
41,176 KB
testcase_35 AC 111 ms
40,024 KB
testcase_36 AC 117 ms
40,736 KB
testcase_37 AC 123 ms
41,384 KB
testcase_38 AC 123 ms
41,204 KB
testcase_39 AC 126 ms
41,476 KB
testcase_40 AC 116 ms
40,660 KB
testcase_41 AC 117 ms
40,736 KB
testcase_42 AC 115 ms
40,204 KB
testcase_43 AC 130 ms
41,096 KB
testcase_44 AC 126 ms
41,568 KB
testcase_45 AC 124 ms
41,248 KB
testcase_46 AC 124 ms
41,228 KB
testcase_47 AC 126 ms
41,272 KB
testcase_48 AC 126 ms
41,368 KB
testcase_49 AC 128 ms
41,340 KB
testcase_50 AC 126 ms
41,292 KB
testcase_51 AC 124 ms
41,124 KB
testcase_52 AC 114 ms
40,200 KB
testcase_53 AC 125 ms
41,508 KB
testcase_54 AC 124 ms
41,060 KB
testcase_55 AC 117 ms
41,040 KB
testcase_56 AC 125 ms
41,320 KB
testcase_57 AC 114 ms
40,356 KB
testcase_58 AC 122 ms
40,976 KB
testcase_59 AC 112 ms
40,168 KB
testcase_60 AC 112 ms
40,020 KB
testcase_61 AC 128 ms
41,224 KB
testcase_62 AC 112 ms
40,428 KB
testcase_63 AC 112 ms
40,008 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(1);
		    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