Determine all possible value(s) of a non-leading zero, 5-digit positive integer N that satisfy each of these given conditions:
(i) Product of the digits of N is equal to the sum of its digits.
(ii) N is divisible by the sum of its digits.
(iii) N does NOT contain the digit 3.
Added for completeness:
What is the total number of values of N if we disregard condition (iii)?
The only 5-digit number meeting all criteria is 22112.
Somewhat interestingly, only one number with fewer than 5 digits meets the other criteria: it is 4112
If condition (iii) is removed, then there are 11 solutions. The other 10 solutions
are the combinations of any 5-digit number composed of three 1's and two 3's.
11133
11313
11331
13113
13131
13311
22112
31113
31131
31311
33111
--------- Python code ---------
def sod(n):
""" Input an integer. Returns the Sum of the Digits """
aList = list(str(n))
ans = 0
for c in aList:
ans = ans + int(c)
return ans
def pod(n):
""" Input an integer. Returns the Product of the Digits """
aList = list(str(n))
ans = 1
for c in aList:
ans = ans * int(c)
return ans
count = 0
power = 4
for n in range(10**power,10**(power+1)):
s = sod(n)
if s != pod(n):
continue
if n%s != 0:
continue
# if '3' in str(n):
# continue
count += 1
print(n)
print(count)
|
Posted by Larry
on 2022-04-24 09:52:46 |