結果

問題 No.300 平方数
ユーザー noriocnorioc
提出日時 2015-11-13 22:40:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 1,451 bytes
コンパイル時間 4,614 ms
コンパイル使用メモリ 108,212 KB
実行使用メモリ 24,364 KB
最終ジャッジ日時 2023-10-11 15:57:11
合計ジャッジ時間 8,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
22,084 KB
testcase_01 AC 68 ms
24,200 KB
testcase_02 AC 68 ms
22,288 KB
testcase_03 AC 66 ms
22,144 KB
testcase_04 AC 67 ms
22,160 KB
testcase_05 AC 68 ms
24,364 KB
testcase_06 AC 68 ms
22,344 KB
testcase_07 AC 68 ms
22,284 KB
testcase_08 AC 67 ms
24,236 KB
testcase_09 AC 68 ms
24,268 KB
testcase_10 AC 68 ms
24,192 KB
testcase_11 AC 67 ms
22,248 KB
testcase_12 AC 68 ms
20,252 KB
testcase_13 AC 69 ms
22,220 KB
testcase_14 AC 68 ms
22,164 KB
testcase_15 AC 68 ms
22,188 KB
testcase_16 AC 68 ms
24,304 KB
testcase_17 AC 68 ms
22,352 KB
testcase_18 AC 69 ms
24,212 KB
testcase_19 AC 68 ms
22,292 KB
testcase_20 AC 67 ms
20,212 KB
testcase_21 AC 69 ms
22,112 KB
testcase_22 AC 69 ms
24,156 KB
testcase_23 AC 69 ms
24,220 KB
testcase_24 AC 69 ms
20,212 KB
testcase_25 AC 69 ms
24,264 KB
testcase_26 AC 69 ms
22,232 KB
testcase_27 AC 70 ms
22,292 KB
testcase_28 AC 69 ms
24,208 KB
testcase_29 AC 70 ms
22,336 KB
testcase_30 AC 70 ms
24,236 KB
testcase_31 AC 70 ms
22,256 KB
testcase_32 AC 72 ms
22,252 KB
testcase_33 AC 70 ms
24,252 KB
testcase_34 AC 69 ms
22,180 KB
testcase_35 AC 69 ms
22,192 KB
testcase_36 AC 70 ms
24,188 KB
testcase_37 AC 69 ms
22,236 KB
testcase_38 AC 68 ms
22,188 KB
testcase_39 AC 68 ms
22,212 KB
testcase_40 AC 68 ms
22,176 KB
testcase_41 AC 69 ms
22,192 KB
testcase_42 AC 69 ms
22,152 KB
testcase_43 AC 68 ms
22,148 KB
testcase_44 AC 69 ms
24,232 KB
testcase_45 AC 69 ms
22,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

static class Prime {
    public static List<int> Sieve(int n) {
        var tab = new bool[n+1];
        var ps = new List<int>();
        if (n >= 2) ps.Add(2);
        for (int i = 3; i <= n; i += 2) {
            if (!tab[i]) { // i is prime
                ps.Add(i);
                for (int j = i+i; j <= n; j += i) {
                    tab[j] = true;
                }
            }
        }
        return ps;
    }
}

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }



    static void Main() {
        var x = long.Parse(ReadLine());
        var primes = Prime.Sieve(1000000);

        var d = new Dictionary<long, int>();
        foreach (int p in primes) {
            if (p * p > x) break;
            while (x % p == 0) {
                if (!d.ContainsKey(p)) d[p] = 0;
                d[p]++;

                x /= p;
            }
        }

        if (x > 1) {
            if (d.ContainsKey(x)) d[x]++;
            else d[x] = 1;
        }

        long ans = 1;
        foreach (var k in d) {
            if (k.Value % 2 == 1) {
                ans *= k.Key;
            }
        }
        Console.WriteLine(ans);
    }
}
0