結果

問題 No.300 平方数
ユーザー bluemeganebluemegane
提出日時 2020-09-10 11:31:59
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,496 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 107,392 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-12-22 23:44:12
合計ジャッジ時間 7,263 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        var x = long.Parse(Console.ReadLine().Trim());
        var m = (int)Sqrt(x) + 1;
        var a = GeneratePrime(m);
        var d = getDic(x, a);
        getAns(d);
    }
    static void getAns(Dictionary<long, int> d)
    {
        var res = 1L;
        foreach (var x in d)
        {
            if (x.Value % 2 == 1) res *= x.Key;
        }
        Console.WriteLine(res);
    }
    static Dictionary<long, int> getDic(long x, List<int> a)
    {
        var acount = a.Count();
        var d = new Dictionary<long, int>();
        for (int i = 0; i < acount; i++)
        {
            if (a[i] > x) break;
            while (true)
            {
                if (x % a[i] == 0)
                {
                    if (d.ContainsKey(a[i])) d[a[i]]++;
                    else d[a[i]] = 1;
                    x /= a[i];
                }
                else break;
            }
        }
        if (d.Count() == 0) d[x] = 1;
        return d;
    }
    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