63 lines
1.2 KiB
Python
63 lines
1.2 KiB
Python
import math
|
|
|
|
start = 123456
|
|
stop = 165432
|
|
|
|
def facteurs(n):
|
|
"""facteurs(n): décomposition d'un nombre entier n en facteurs premiers"""
|
|
F = []
|
|
if n==1:
|
|
return F
|
|
# recherche de tous les facteurs 2 s'il y en a
|
|
while n>=2:
|
|
x,r = divmod(n,2)
|
|
if r!=0:
|
|
break
|
|
F.append(2)
|
|
n = x
|
|
# recherche des facteurs 1er >2
|
|
i=3
|
|
rn = math.sqrt(n)+1
|
|
while i<=n:
|
|
if i>rn:
|
|
F.append(n)
|
|
break
|
|
x,r = divmod(n,i)
|
|
if r==0:
|
|
F.append(i)
|
|
n=x
|
|
rn = math.sqrt(n)+1
|
|
else:
|
|
i += 2
|
|
return F
|
|
|
|
def decomposition(l):
|
|
new = dict()
|
|
|
|
for i in l:
|
|
if i not in new:
|
|
new[i] = 1
|
|
else:
|
|
new[i] = new[i]+1
|
|
|
|
decomp = 0
|
|
for key in new:
|
|
decomp = decomp + len(str(key))
|
|
if new[key] >= 10:
|
|
decomp = decomp + 2
|
|
elif new[key] > 1:
|
|
decomp = decomp + 1
|
|
|
|
return decomp
|
|
|
|
|
|
choix = 0
|
|
for i in range(start, stop+1):
|
|
fact = facteurs(i)
|
|
chiffres = len(str(i))
|
|
decomp = decomposition(fact)
|
|
if chiffres > decomp:
|
|
choix = choix + 1
|
|
print(i, chiffres, fact, decomp)
|
|
|
|
print("Choix :", choix) |