結果

問題 No.36 素数が嫌い!
ユーザー bluemeganebluemegane
提出日時 2020-09-07 14:09:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 938 ms
コンパイル使用メモリ 113,380 KB
実行使用メモリ 72,488 KB
最終ジャッジ日時 2024-11-29 10:42:26
合計ジャッジ時間 35,535 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 5 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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