結果

問題 No.8023 素数判定するだけ
ユーザー ruuuuutopia
提出日時 2021-06-01 22:03:24
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 7,511 ms
コンパイル使用メモリ 165,560 KB
実行使用メモリ 184,376 KB
最終ジャッジ日時 2024-11-09 00:18:32
合計ジャッジ時間 13,606 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 24 MLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            if (IsPrime(N) == true)
            {
                Console.WriteLine("YES");
            }else
                Console.WriteLine("NO");

        }
        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}
0