結果
| 問題 |
No.889 素数!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-19 16:38:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| コード長 | 1,886 bytes |
| コンパイル時間 | 2,308 ms |
| コンパイル使用メモリ | 77,608 KB |
| 実行使用メモリ | 41,596 KB |
| 最終ジャッジ日時 | 2024-10-12 04:58:56 |
| 合計ジャッジ時間 | 10,901 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
ソースコード
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;
}
}