結果
| 問題 |
No.1063 ルートの計算 / Sqrt Calculation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-21 13:15:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 931 bytes |
| コンパイル時間 | 91 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-06-30 23:31:51 |
| 合計ジャッジ時間 | 1,426 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
from itertools import count
def calc_positive_divisors(num: int) -> dict[int, int]:
if num < 2:
raise ValueError
divisors = {}
for divisor in count(2):
if divisor ** 2 > num:
if num != 1:
divisors[num] = 1
break
while num % divisor == 0 and num != 1:
try:
divisors[divisor] += 1
except KeyError:
divisors[divisor] = 1
num //= divisor
return divisors
def main():
N = int(input())
match N:
case 1:
print(1, 1)
case 2:
print(1, 2)
case num:
a, b = 1, 1
divisors = calc_positive_divisors(num)
for divisor, count_ in divisors.items():
a *= divisor ** (count_ // 2)
b *= divisor ** (count_ % 2)
print(a, b)
if __name__ == "__main__":
main()