結果

問題 No.300 平方数
ユーザー maspymaspy
提出日時 2022-04-25 05:41:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 1,779 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 13,276 KB
最終ジャッジ日時 2023-09-09 07:31:32
合計ジャッジ時間 4,300 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
12,432 KB
testcase_01 AC 42 ms
12,364 KB
testcase_02 AC 108 ms
13,252 KB
testcase_03 AC 42 ms
12,440 KB
testcase_04 AC 44 ms
12,472 KB
testcase_05 AC 41 ms
12,440 KB
testcase_06 AC 42 ms
12,384 KB
testcase_07 AC 41 ms
12,412 KB
testcase_08 AC 41 ms
12,424 KB
testcase_09 AC 42 ms
12,432 KB
testcase_10 AC 42 ms
12,616 KB
testcase_11 AC 43 ms
12,452 KB
testcase_12 AC 44 ms
13,236 KB
testcase_13 AC 44 ms
13,256 KB
testcase_14 AC 45 ms
13,072 KB
testcase_15 AC 44 ms
13,160 KB
testcase_16 AC 44 ms
13,212 KB
testcase_17 AC 43 ms
13,216 KB
testcase_18 AC 43 ms
13,080 KB
testcase_19 AC 45 ms
13,260 KB
testcase_20 AC 45 ms
13,112 KB
testcase_21 AC 44 ms
13,276 KB
testcase_22 AC 43 ms
13,208 KB
testcase_23 AC 44 ms
13,252 KB
testcase_24 AC 45 ms
13,144 KB
testcase_25 AC 46 ms
13,148 KB
testcase_26 AC 46 ms
13,064 KB
testcase_27 AC 44 ms
13,276 KB
testcase_28 AC 44 ms
13,064 KB
testcase_29 AC 44 ms
13,072 KB
testcase_30 AC 43 ms
13,072 KB
testcase_31 AC 44 ms
13,164 KB
testcase_32 AC 44 ms
13,208 KB
testcase_33 AC 44 ms
13,216 KB
testcase_34 AC 44 ms
13,144 KB
testcase_35 AC 44 ms
13,268 KB
testcase_36 AC 43 ms
13,120 KB
testcase_37 AC 43 ms
13,112 KB
testcase_38 AC 44 ms
13,216 KB
testcase_39 AC 43 ms
13,112 KB
testcase_40 AC 44 ms
13,204 KB
testcase_41 AC 43 ms
13,256 KB
testcase_42 AC 44 ms
13,220 KB
testcase_43 AC 45 ms
13,216 KB
testcase_44 AC 43 ms
13,080 KB
testcase_45 AC 44 ms
13,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from math import gcd
from functools import reduce
from operator import mul

def MillerRabinTest(n, maxiter = 10):
    import random
    if n == 1:
        return False
    elif n == 2:
        return True
    if not n&1:
        return False
    d = n - 1
    while not (d & 1):
        d >>= 1
        
    for _ in range(maxiter):
        a = random.randint(1,n-1)
        t = d
        x = pow(a,t,n)
        while (t != n-1) and (x != 1) and (x != n - 1):
            x = x * x % n
            t <<= 1
        if (x != n-1) and not (t & 1):
            return False
    return True

U = 10 ** 5
pf = list(range(U))
for n in range(2,U,2):
    pf[n] = 2
sq = int(U ** .5) + 1
for p in range(3,sq,2):
    if pf[p] == p:
        for i in range(p*p,U,p+p):
            pf[i] = p

def pollard_rho(n):
    f = 0
    while True:
        f += 1
        x, y = 2, 2
        while True:
            x = (x*x + f) % n
            y = (y*y + f) % n
            y = (y*y + f) % n
            d = gcd(x - y, n)
            if d != 1:
                break
        if d == n:
            continue
        return d

def _factor(N):
    if N == 1:
        return
    while N != 1:
        if N < U:
            p = pf[N]
            yield p; N //= p
            continue
        if MillerRabinTest(N,maxiter=15):
            yield N
            return
        d = pollard_rho(N)
        for x in _factor(d):
            yield x
        N //= d

def factor(N):
    f = list(_factor(N))
    f.sort()
    return f

N = int(read())

f = factor(N)

se = set()
for p in f:
    if p not in se:
        se.add(p)
    else:
        se.remove(p)

answer = reduce(mul,se,1)
print(answer)
0