您的位置:首页 > 其它

Digit cancelling fractions

2016-04-24 21:54 288 查看

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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: