用python写出平方数的素因子去重后按从小到大顺序输出的代码
时间: 2024-05-03 13:20:52 浏览: 109
使用python实现素数判断
Sure, here is the Python code to find prime factors of a given number and remove duplicates, then sort them in ascending order before outputting:
```
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return set(factors)
n = int(input("Enter a number: "))
prime_factors_list = sorted(list(prime_factors(n)))
print(prime_factors_list)
```
Hope this helps!
阅读全文