[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2023-08-06 15:19:52 +00:00
parent 2590a893f8
commit 2a37bbf8c5

View File

@ -1,9 +1,9 @@
from __future__ import annotations from __future__ import annotations
from math import ceil , sqrt from math import ceil, sqrt
def primeproduct( num : int) -> list[int]:
''' def primeproduct(num: int) -> list[int]:
"""
>>> primeproduct(868) >>> primeproduct(868)
[2, 2, 7, 31] [2, 2, 7, 31]
>>> primeproduct(9039423423423743) >>> primeproduct(9039423423423743)
@ -13,47 +13,46 @@ def primeproduct( num : int) -> list[int]:
ValueError: invalid literal for int() with base 10: '0.02' ValueError: invalid literal for int() with base 10: '0.02'
>>> primeproduct(-2342) >>> primeproduct(-2342)
[] []
''' """
if num <= 1: if num <= 1:
return [] return []
prime_factors = [] prime_factors = []
while num > 1: while num > 1:
if len(prime_factors) >= 1 and prime_factors[-1] % num ==0: if len(prime_factors) >= 1 and prime_factors[-1] % num == 0:
prime_factors.append(prime_factors[-1]) prime_factors.append(prime_factors[-1])
else: else:
sq = ceil(sqrt(num)) sq = ceil(sqrt(num))
flag = 0 flag = 0
if prime_factors!=[]: if prime_factors != []:
for i in range(prime_factors[-1], sq+1 , 2): for i in range(prime_factors[-1], sq + 1, 2):
if num % i == 0: if num % i == 0:
num = num // i num = num // i
prime_factors.append(i) prime_factors.append(i)
flag = 1 flag = 1
break break
else: else:
while num % 2 == 0: while num % 2 == 0:
num = num // 2 num = num // 2
prime_factors.append(2) prime_factors.append(2)
for i in range(3 , sq+1 , 2): for i in range(3, sq + 1, 2):
if num % i == 0: if num % i == 0:
num = num // i num = num // i
prime_factors.append(i) prime_factors.append(i)
flag = 1 flag = 1
break break
if not flag and num > 1: if not flag and num > 1:
prime_factors.append(num) prime_factors.append(num)
num = 1 num = 1
break break
return prime_factors return prime_factors