結果
| 問題 |
No.36 素数が嫌い!
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2020-09-07 14:20:34 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,234 bytes |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 107,904 KB |
| 実行使用メモリ | 58,240 KB |
| 最終ジャッジ日時 | 2024-11-29 10:43:45 |
| 合計ジャッジ時間 | 35,484 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 WA * 1 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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++;
n /= x;
//Console.WriteLine("x = {0} nn = {1}",x,n);
if (count >= 2) { Console.WriteLine("YES"); return; }
}
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;
}
}
bluemegane