結果

問題 No.889 素数!
ユーザー bluemegane
提出日時 2021-04-19 07:39:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 107,756 KB
実行使用メモリ 26,064 KB
最終ジャッジ日時 2024-07-04 04:58:29
合計ジャッジ時間 3,828 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void getAns(int n)
    {
        string ans;
        if (IsPrime(n)) ans = "Sosu!";
        else if (n == 4 | n == 9 | n == 16 | n == 25 | n == 36 |
                   n == 49) ans = "Heihosu!";
        else if (n == 8 | n == 27) ans = "Ripposu!";
        else if (n == 6 | n == 28) ans = "Kanzensu!";
        else ans = n.ToString();
        Console.WriteLine(ans);
    }
    static bool IsPrime(int n)
    {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n % 2 == 0) return false;
        double sqrtNum = Sqrt(n);
        for (int i = 3; i <= sqrtNum; i += 2)
            if (n % i == 0) return false;
        return true;
    }
}
0