結果

問題 No.889 素数!
ユーザー face4face4
提出日時 2019-09-16 16:28:29
言語 Java
(openjdk 23)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 2,551 ms
コンパイル使用メモリ 77,608 KB
実行使用メモリ 54,296 KB
最終ジャッジ日時 2024-07-07 02:25:24
合計ジャッジ時間 12,036 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{
    static boolean isPrime(int x){
        if(x < 2)   return false;
        for(int i = 2; i < x; i++){
            if(x % i == 0)  return false;
        }
        return true;
    }

    static boolean isSquare(int x){
        for(int i = 1; i*i <= x; i++){
            if(i*i == x)    return true;
        }
        return false;
    }

    static boolean isCubic(int x){
        for(int i = 1; i*i*i <= x; i++){
            if(i*i*i == x)  return true;
        }
        return false;
    }

    static boolean isPerfect(int x){
        int sum = 0;
        for(int i = 1; i <= x; i++){
            if(x%i == 0)    sum += i;
        }
        return (sum == x+x);
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String ans = "";
        if(n < 2)               ans = String.valueOf(n);
        else if(isPrime(n))     ans = "Sosu!";
        else if(isSquare(n))    ans = "Heihosu!";
        else if(isCubic(n))     ans = "Ripposu!";
        else if(isPerfect(n))   ans = "Kanzensu!";
        else                    ans = String.valueOf(n);
        System.out.println(ans);
    }
}
0