L-B number is a number with distinct non-zero digits
divisible by each of its digits e.g. 186432.
a. What is the largest LBN not containing the digit 1?
b. How many LBNs contain the digit 4?
c. Same for digit 5.
d. What is the largest LBN?
Provide your reasoning and/or program; solution by searching for answers on the web will be considered unfair…
The largest LBN without a 1 is 978264
The number of LBNs containing the digit 4 is 339
The number of LBNs containing the digit 5 is 12
The largest LBN is 9867312
---------------
def isLynchBell(n):
""" Lynch-Bell numbers
L-B number is a number with distinct non-zero digits divisible by each of its digits """
st = str(n)
if '0' in st:
return False
if len(set(st)) != len(st):
return False
for c in st:
if (n/int(c))%1 != 0:
return False
return True
lbns = [i for i in range(987654322) if isLynchBell(i)]
foundWithoutOne = False
howmanyfours = 0
howmanyfives = 0
for lbn in reversed(lbns):
st = str(lbn)
if not foundWithoutOne:
if '1' not in st:
print('The largest LBN without a 1 is', lbn)
foundWithoutOne = True
if '4' in st:
howmanyfours += 1
if '5' in st:
howmanyfives += 1
print('The number of LBNs containing the digit 4 is', howmanyfours)
print('The number of LBNs containing the digit 5 is', howmanyfives)
print('The largest LBN is',lbns[-1])
|
Posted by Larry
on 2023-01-27 08:30:55 |