結果

問題 No.889 素数!
ユーザー michonz4
提出日時 2019-12-30 19:01:52
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 792 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-14 07:14:02
合計ジャッジ時間 1,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 30 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdbool.h>
#include <math.h>
bool isPrime(int n) {
  if (n==2) {
    return true;
  } else if (n<2 || n%2==0) {
    return false;
  }
  for (int i=3; i*i<=n; i+=2) {
    if (n%i==0) {
      return false;
    }
  }
  return true;
}

bool kanzen(int n) {
  int sum=0;
  for (int i=1; i*i<=n; i++) {
    if (n%i==0) {
      sum+=i;
      if (i*i!=n) sum+=n/i;
    }
  }
  return sum-n==n ? true: false;
}

int main() {
  int n;
  scanf("%d", &n);

  if (isPrime(n)) {
    printf("Sosu!\n");
  } else if ((int)pow(pow(n, 1.0/2.0), 2)==n && n>1) {
    printf("Heihosu!\n");
  } else if ((int)pow(pow(n, 1.0/3.0), 3.0)==n && n>1) {
    printf("Ripposu!\n");
  } else if (kanzen(n) && n>1) {
    printf("Kanzensu!\n");
  } else {
    printf("%d\n", n);
  }
  return 0;
}
0