結果

問題 No.300 平方数
ユーザー hiragnhiragn
提出日時 2022-11-19 00:33:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 1,000 ms
コード長 1,542 bytes
コンパイル時間 452 ms
コンパイル使用メモリ 11,964 KB
実行使用メモリ 10,592 KB
最終ジャッジ日時 2023-10-20 09:20:33
合計ジャッジ時間 3,804 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,592 KB
testcase_01 AC 32 ms
10,592 KB
testcase_02 AC 32 ms
10,592 KB
testcase_03 AC 31 ms
10,588 KB
testcase_04 AC 31 ms
10,592 KB
testcase_05 AC 32 ms
10,592 KB
testcase_06 AC 31 ms
10,592 KB
testcase_07 AC 32 ms
10,592 KB
testcase_08 AC 31 ms
10,592 KB
testcase_09 AC 32 ms
10,592 KB
testcase_10 AC 31 ms
10,592 KB
testcase_11 AC 32 ms
10,592 KB
testcase_12 AC 32 ms
10,592 KB
testcase_13 AC 36 ms
10,592 KB
testcase_14 AC 31 ms
10,592 KB
testcase_15 AC 31 ms
10,592 KB
testcase_16 AC 31 ms
10,592 KB
testcase_17 AC 31 ms
10,592 KB
testcase_18 AC 31 ms
10,592 KB
testcase_19 AC 31 ms
10,592 KB
testcase_20 AC 32 ms
10,592 KB
testcase_21 AC 32 ms
10,592 KB
testcase_22 AC 32 ms
10,592 KB
testcase_23 AC 35 ms
10,592 KB
testcase_24 AC 34 ms
10,592 KB
testcase_25 AC 34 ms
10,592 KB
testcase_26 AC 35 ms
10,592 KB
testcase_27 AC 33 ms
10,592 KB
testcase_28 AC 33 ms
10,592 KB
testcase_29 AC 33 ms
10,592 KB
testcase_30 AC 33 ms
10,592 KB
testcase_31 AC 34 ms
10,592 KB
testcase_32 AC 35 ms
10,592 KB
testcase_33 AC 34 ms
10,592 KB
testcase_34 AC 35 ms
10,592 KB
testcase_35 AC 34 ms
10,592 KB
testcase_36 AC 34 ms
10,592 KB
testcase_37 AC 34 ms
10,592 KB
testcase_38 AC 33 ms
10,592 KB
testcase_39 AC 33 ms
10,592 KB
testcase_40 AC 33 ms
10,592 KB
testcase_41 AC 35 ms
10,592 KB
testcase_42 AC 33 ms
10,592 KB
testcase_43 AC 35 ms
10,592 KB
testcase_44 AC 33 ms
10,592 KB
testcase_45 AC 33 ms
10,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict
from functools import reduce
from operator import mul


def is_prime(n):
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True


def prime_fact(N):
    res = defaultdict(int)
    if N == 1:
        return res
    p = 2
    while p <= 10 ** 4 and N > 1:
        if N % p == 0:
            while N % p == 0:
                res[p] += 1
                N //= p
        p += 1
    while N > 1:
        if is_prime(N):
            res[N] += 1
            break
        x = random.randrange(N)
        y = (x * x + 1) % N
        i = 1
        while True:
            d = gcd(abs(x - y), N)
            if d == 1:
                i += 1
            elif d == N:
                res[N] += 1
                return res
            else:
                res[d] += 1
                N //= d
                break
            x = (x * x + 1) % N
            y = (y * y + 1) % N
            y = (y * y + 1) % N
    return res


def main():
    n = int(input())

    lst = [1] + [p for p, k in prime_fact(n).items() if k % 2 == 1]
    ans = reduce(mul, lst)
    print(ans)


if __name__ == "__main__":
    main()
0