結果

問題 No.300 平方数
ユーザー rpy3cpp
提出日時 2015-11-13 22:24:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 156 ms / 1,000 ms
コード長 667 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-13 14:37:50
合計ジャッジ時間 3,532 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import collections

def factorize(n):
    ''' returns a list of prime factors of n.
    ex. factorize(24) = [2, 2, 2, 3]
    source: Rossetta code: prime factorization (slightly modified)
    http://rosettacode.org/wiki/Prime_decomposition#Python:_Using_floating_point
    '''
    step = lambda x: 1 + (x<<2) - ((x>>1)<<1)
    maxq = int(math.floor(math.sqrt(n)))
    d = 1
    q = n % 2 == 0 and 2 or 3
    while q <= maxq and n % q != 0:
        q = step(d)
        d += 1
    return q <= maxq and [q] + factorize(n//q) or [n]

X = int(input())
fac = collections.Counter(factorize(X))
Y = 1
for p, k in fac.items():
    if k & 1:
        Y *= p
print(Y)
0