結果
| 問題 |
No.300 平方数
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-01-06 23:15:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,782 bytes |
| コンパイル時間 | 110 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,648 KB |
| 最終ジャッジ日時 | 2024-11-23 00:21:35 |
| 合計ジャッジ時間 | 3,343 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 43 |
ソースコード
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)
print(answer)
maspy