結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー RiburaRibura
提出日時 2020-05-29 21:34:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,058 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 821,132 KB
最終ジャッジ日時 2024-04-23 20:25:09
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,496 KB
testcase_01 AC 25 ms
10,752 KB
testcase_02 AC 25 ms
10,624 KB
testcase_03 RE -
testcase_04 AC 27 ms
10,624 KB
testcase_05 RE -
testcase_06 AC 603 ms
95,360 KB
testcase_07 RE -
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter


class Prime_Decomposition:
    def __init__(self, n_max):
        self.min_factor = min_factor = list(range(n_max + 1))
        for i in range(2, int(n_max ** 0.5) + 1):
            if min_factor[i] == i:
                for j in range(i * i, n_max + 1, i):
                    if min_factor[j] == j:
                        min_factor[j] = i

    def __call__(self, n):
        min_factor = self.min_factor
        n_twoes = (n & -n).bit_length() - 1  # 最悪ケースでは速くなる
        res = [2] * n_twoes
        n >>= n_twoes
        while n > 1:
            p = min_factor[n]
            res.append(p)
            n //= p
        return res


n = int(readline())
prime_check = Prime_Decomposition(n + 1)
a = 1
b = 1
for k, v in Counter(prime_check(n)).items():
    x, y = divmod(v, 2)
    if x != 0:
        a *= k ** x
    if y != 0:
        b *= k
print(a, b)
0