結果
| 問題 | 
                            No.300 平方数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maspy
                         | 
                    
| 提出日時 | 2022-04-25 05:41:11 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 148 ms / 1,000 ms | 
| コード長 | 1,779 bytes | 
| コンパイル時間 | 268 ms | 
| コンパイル使用メモリ | 12,928 KB | 
| 実行使用メモリ | 15,360 KB | 
| 最終ジャッジ日時 | 2024-06-27 00:39:54 | 
| 合計ジャッジ時間 | 4,353 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 43 | 
ソースコード
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)
            
            
            
        
            
maspy