結果
| 問題 |
No.1737 One to N
|
| コンテスト | |
| ユーザー |
hiragn
|
| 提出日時 | 2022-11-03 01:28:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,449 bytes |
| コンパイル時間 | 93 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-07-17 13:00:23 |
| 合計ジャッジ時間 | 2,446 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
from math import gcd
import random
from collections import defaultdict
def is_prime(n):
if n == 2:
return True
if n == 1 or n & 1 == 0:
return False
d = (n - 1) >> 1
while d & 1 == 0:
d >>= 1
for k in range(100):
a = random.randint(1, n - 1)
t = d
y = pow(a, t, n)
while t != n - 1 and y != 1 and y != n - 1:
y = (y * y) % n
t <<= 1
if y != n - 1 and t & 1 == 0:
return False
return True
def prime_fact(n):
res = defaultdict(int)
if n == 1:
return res
p = 2
while p <= 10 ** 4 and n > 1:
if n % p == 0:
while n % p == 0:
res[p] += 1
n //= p
p += 1
while n > 1:
if is_prime(n):
res[n] += 1
break
x = random.randrange(n)
y = (x * x + 1) % n
i = 1
while True:
d = gcd(abs(x - y), n)
if d == 1:
i += 1
elif d == n:
res[n] += 1
return res
else:
res[d] += 1
n //= d
break
x = (x * x + 1) % n
y = (y * y + 1) % n
y = (y * y + 1) % n
return res
def main():
n = int(input())
ans = sum([x * y for x, y in prime_fact(n).items()])
print(ans)
if __name__ == "__main__":
main()
hiragn