結果
| 問題 |
No.889 素数!
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-02-13 18:09:46 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 1,428 bytes |
| コンパイル時間 | 2,358 ms |
| コンパイル使用メモリ | 77,284 KB |
| 実行使用メモリ | 55,100 KB |
| 最終ジャッジ日時 | 2024-10-06 06:16:25 |
| 合計ジャッジ時間 | 12,144 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
ソースコード
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(n);
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;
}
}
htensai