結果

問題 No.300 平方数
ユーザー keymoon
提出日時 2021-02-01 22:44:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 891 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 112,320 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-06-29 23:29:53
合計ジャッジ時間 3,703 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        long x = long.Parse(Console.ReadLine());
        Console.WriteLine(PrimeFactors(x).GroupBy(x => x).Where(x => x.Count() % 2 == 1).Aggregate(1L, (x, y) => x * y.Key));
    }

    static IEnumerable<long> PrimeFactors(long n)
    {
        while ((n & 1) == 0)
        {
            n >>= 1;
            yield return 2;
        }
        for (long i = 3; i * i <= n; i += 2)
        {
            while (n % i == 0)
            {
                n /= i;
                yield return i;
            }
        }
        if (n != 1) yield return n;
    }
}
0