結果
| 問題 |
No.300 平方数
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2020-09-10 11:35:33 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 197 ms / 1,000 ms |
| コード長 | 1,475 bytes |
| コンパイル時間 | 3,789 ms |
| コンパイル使用メモリ | 113,552 KB |
| 実行使用メモリ | 22,528 KB |
| 最終ジャッジ日時 | 2024-12-22 23:55:02 |
| 合計ジャッジ時間 | 10,329 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / 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.
ソースコード
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;
}
}
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;
}
}
bluemegane