結果

問題 No.889 素数!
ユーザー yukiyuki
提出日時 2020-08-19 16:38:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,886 bytes
コンパイル時間 2,335 ms
コンパイル使用メモリ 77,856 KB
実行使用メモリ 54,492 KB
最終ジャッジ日時 2024-04-20 09:32:37
合計ジャッジ時間 10,797 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
53,848 KB
testcase_01 AC 118 ms
53,980 KB
testcase_02 AC 120 ms
54,028 KB
testcase_03 AC 120 ms
54,036 KB
testcase_04 AC 109 ms
53,056 KB
testcase_05 AC 121 ms
54,120 KB
testcase_06 AC 120 ms
54,032 KB
testcase_07 AC 101 ms
52,676 KB
testcase_08 AC 119 ms
54,204 KB
testcase_09 AC 117 ms
54,052 KB
testcase_10 AC 128 ms
54,120 KB
testcase_11 AC 117 ms
53,980 KB
testcase_12 AC 117 ms
54,216 KB
testcase_13 AC 120 ms
54,148 KB
testcase_14 AC 116 ms
54,112 KB
testcase_15 AC 116 ms
54,108 KB
testcase_16 AC 109 ms
53,228 KB
testcase_17 AC 120 ms
54,160 KB
testcase_18 AC 105 ms
53,084 KB
testcase_19 AC 113 ms
54,416 KB
testcase_20 AC 113 ms
54,492 KB
testcase_21 AC 107 ms
53,016 KB
testcase_22 AC 111 ms
54,324 KB
testcase_23 AC 111 ms
53,932 KB
testcase_24 AC 114 ms
53,880 KB
testcase_25 AC 110 ms
53,108 KB
testcase_26 AC 114 ms
54,336 KB
testcase_27 AC 103 ms
53,036 KB
testcase_28 AC 101 ms
52,728 KB
testcase_29 AC 111 ms
54,056 KB
testcase_30 AC 100 ms
52,892 KB
testcase_31 AC 118 ms
54,072 KB
testcase_32 AC 123 ms
54,228 KB
testcase_33 AC 120 ms
54,168 KB
testcase_34 AC 116 ms
53,888 KB
testcase_35 AC 97 ms
52,516 KB
testcase_36 AC 114 ms
54,248 KB
testcase_37 AC 113 ms
54,368 KB
testcase_38 AC 126 ms
54,112 KB
testcase_39 AC 118 ms
54,140 KB
testcase_40 AC 119 ms
54,172 KB
testcase_41 AC 121 ms
54,168 KB
testcase_42 AC 105 ms
53,084 KB
testcase_43 AC 121 ms
54,352 KB
testcase_44 AC 119 ms
54,316 KB
testcase_45 AC 114 ms
54,044 KB
testcase_46 AC 105 ms
53,104 KB
testcase_47 AC 115 ms
54,276 KB
testcase_48 AC 112 ms
54,028 KB
testcase_49 AC 103 ms
54,124 KB
testcase_50 AC 116 ms
53,980 KB
testcase_51 AC 114 ms
54,144 KB
testcase_52 AC 115 ms
54,000 KB
testcase_53 AC 117 ms
54,248 KB
testcase_54 AC 103 ms
52,740 KB
testcase_55 AC 99 ms
52,892 KB
testcase_56 AC 115 ms
54,036 KB
testcase_57 AC 122 ms
54,432 KB
testcase_58 AC 104 ms
52,928 KB
testcase_59 AC 112 ms
53,388 KB
testcase_60 AC 112 ms
54,260 KB
testcase_61 AC 105 ms
53,020 KB
testcase_62 AC 118 ms
54,108 KB
testcase_63 AC 106 ms
53,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
		int N = in.nextInt();
		int a = (int)Math.sqrt(N);  // square number

        if(isPrime(N)){
            System.out.println("Sosu!");
        }else if(isSQnum(N, a)){
            System.out.println("Heihosu!");            
        }else if(isQubicNum(N)){
            System.out.println("Ripposu!");
        }else if(isPerfect(N)){
            System.out.println("Kanzensu!");
        }else{
            System.out.println(N);            
        }
        
   }
   
    static boolean isPrime(int N){
        if(N == 0 || N == 1)
            return false;
        if(N == 2)
            return true;
        else{
            // N(判定する数)までで、割り切れる数があれば、
            // それは素数ではない
            for(int i=2; i<N; i++){
                if(N % i == 0){
                    return false;
                }
            }
            return true;
        }        

    }
    
    static boolean isSQnum(int N, int a){
        if(N>=2 && a*a == N){
            return true;
        }
        return false;
    }
    
    static boolean isQubicNum(int N){
        if(Math.pow(N, 1.0 / 3) >= 2.0){
            double root = Math.pow(N, 1.0 / 3);
            if(root - Math.floor(root) == 0)
                return true;
            else
                return false;
        }
        return false;
    }
    
    static boolean isPerfect(int N){
        if(N == 0)
            return false;
            
        int sum = 0;
        for(int i=1; i <= N/2; i++){
            if(N % i == 0){
                sum += i;
            }
        }
        if(sum == N) {
            return true;
        }
        return false;
        
    }

}
0