马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
很烂,将就着用吧from math import floor, sqrt
def isPrime(n: int, /) -> bool:
if isinstance(n, int) and n>0:
if n==2 or n==3:
return True
temp=n%6
if n==1 or not n&1 or temp!=1 and temp!=5:
return False
for i in range(3,floor(sqrt(n))+1,2):
if not n%i:
return False
return True
else:
raise TypeError("an positive integer is required")
def intFactorization(n: int, /) -> 'generator':
if isinstance(n, int) and n>0:
while not n&1:
n>>=1
yield 2
temp=3
maximum=floor(sqrt(n))
while temp<=maximum:
if not n%temp:
while not n%temp:
n//=temp
yield temp
maximum=floor(sqrt(n))
temp+=2
if n!=1:
yield n
else:
raise TypeError("an positive integer is required")
def intFactorization(n: int, /) -> list:
if isinstance(n, int) and n>0:
res=[]
while not n&1:
n>>=1
res.append(2)
temp=3
maximum=floor(sqrt(n))
while temp<=maximum:
if not n%temp:
while not n%temp:
n//=temp
res.append(temp)
maximum=floor(sqrt(n))
temp+=2
if n!=1:
res.append(n)
return res
else:
raise TypeError("an positive integer is required")
|