結果

問題 No.300 平方数
ユーザー maspymaspy
提出日時 2020-01-06 23:17:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,784 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 9,988 KB
最終ジャッジ日時 2023-08-14 22:57:40
合計ジャッジ時間 2,992 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

from fractions 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