結果

問題 No.36 素数が嫌い!
ユーザー bluemeganebluemegane
提出日時 2020-09-07 14:09:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 65,908 KB
実行使用メモリ 65,680 KB
最終ジャッジ日時 2023-08-19 16:44:46
合計ジャッジ時間 34,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 46 ms
22,836 KB
testcase_03 WA -
testcase_04 AC 45 ms
20,696 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 53 ms
21,732 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 651 ms
34,244 KB
testcase_12 AC 2,670 ms
63,500 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 45 ms
20,692 KB
testcase_17 AC 44 ms
20,780 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        if (n <= 5) { Console.WriteLine("NO"); goto exit; }
        var a = GeneratePrime((int)Sqrt(n));
        getAns(n, a);
    exit:;
    }
    static void getAns(long n, List<int> a)
    {
        var count = 0;
        foreach (var x in a)
        {
            while (true)
            {
                if (n % x == 0)
                {
                    count++;
                    if (count >= 2) { Console.WriteLine("YES"); return; }
                    n /= x;
                    Console.WriteLine("x = {0} nn = {1}",x,n);
                }
                else break;
            }
        }
        Console.WriteLine("NO");
    }
    static List<int> GeneratePrime(int m)
    {
        var a = new List<int>();
        int p;
        var sqrtMax = Math.Sqrt(m);
        var s = Enumerable.Range(2, m - 1).ToList();
        do
        {
            p = s.First();
            a.Add(p);
            s.RemoveAll(n => n % p == 0);
        }
        while (p < sqrtMax);
        a.AddRange(s);
        return a;
    }
}
0