Digit cancelling fractions
Problem 33
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
考虑的比较简单,可消去的数字只有1-9共9个,另外的数字,组合方案总共9*9个,每一个组合,有4中匹配,遍历一下即可.
def DigitCancellingFractions():
result = set()
for i in range(1,10):
for j in range(1,10):
for k in range(1,10):
tmp1 = i * 10 + j
tmp2 = i * 10 + k
tmp3 = j * 10 + i
tmp4 = k * 10 + i
if tmp1 < tmp2 and tmp1 / tmp2== j / k:
result.add((j,k))
if tmp3 < tmp2 and tmp3 / tmp2== j / k:
result.add((j,k))
if tmp1 < tmp4 and tmp1 / tmp4== j / k:
result.add((j,k))
if tmp3 < tmp4 and tmp3 / tmp4== j / k:
result.add((j,k))
print(result)
DigitCancellingFractions()
本文探讨了一种特殊的分数简化方式,即通过取消分子与分母中的相同数字来得到等值分数的问题。文中给出了一个具体的例子,并提供了一段Python代码来找出所有符合条件的分数并计算这些分数乘积的分母值。
613

被折叠的 条评论
为什么被折叠?



