Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def product(seq):
- result = 1
- for item in seq:
- result *= item
- return result
- def d(x):
- while x > 9:
- x = product(int(c) for c in str(x))
- return x
- def count_failing_cases(n):
- total = 0
- for a in range(1, n+1):
- for b in range(1, n+1):
- for c in range(1, n+1):
- if d(a*b) == c and a*b != c:
- total += 1
- elif d(a*b) != c and a*b == c:
- total += 1
- return total
- for n in [4, 5]:
- print(f"count_failing_cases({n}) = {count_failing_cases(n)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement