結果

問題 No.889 素数!
ユーザー yuki
提出日時 2020-08-19 16:26:53
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,770 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 43,220 KB
最終ジャッジ日時 2024-10-12 04:55:29
合計ジャッジ時間 11,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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 == 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){
        int sum = 0;
        for(int i=1; i<N/2; i++){
            if(N % 2 == 0){
                sum += N;
            }
        }
        if(sum == N) {
            return true;
        }
        return false;
        
    }

}
0