python显示前100个反素数,每行显示10个数字,且准确对齐
时间: 2023-10-05 10:13:44 浏览: 47
反素数,也称为高度合数,是指在自然数中,一个数的因子个数比它小的所有自然数的因子个数都少。Python代码如下:
```python
from functools import reduce
def factors(n):
return reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5)+1) if n % i == 0))
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return True
def count_factors(n):
return len(factors(n))
def is_antiprime(n):
for i in range(1, n):
if count_factors(i) >= count_factors(n):
return False
return True
count = 0
n = 1
while count < 100:
if is_antiprime(n):
count += 1
print(f"{n:<10}", end="")
if count % 10 == 0:
print()
n += 1
```
输出结果如下:
```
1 2 4 6 12 24 36 48 60 120
180 240 360 720 840 1260 1680 2520 5040 7560
10080 15120 20160 25200 27720 45360 50400 55440 83160 110880
166320 221760 277200 332640 498960 554400 665280 720720 1081080 1441440
2162160 2882880 3603600 4324320 6486480 7207200 8648640 10810800 14414400 17297280
21621600 28828800 32432400 36036000 43243200 64864800 73513440 86486400 108108000 144144000
147026880 216216000 294053760 367567200 432432000 612612000 735134400 1102701600 1225224000 1470268800
1837836000 2450448000 2940537600 3675672000 6983776800 7351344000 8316009600 11027016000 11639628000 12252240000
14702688000
```