Problem 33 Digit cancelling fractions

2016-10-14 09:03:00   技术   projecteulor python

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.


消去数字的分数

49/98是一个有趣的分数,因为缺乏经验的数学家可能在约简时错误地认为,等式49/98 = 4/8之所以成立,是因为在分数线上下同时抹除了9的缘故。

我们也会想到,存在诸如30/50 = 3/5这样的平凡解。

这类有趣的分数恰好有四个非平凡的例子,它们的分数值小于1,且分子和分母都是两位数。

将这四个分数的乘积写成最简分数,求此时分母的值。

for a in range(10, 99):
    for b in range(a + 1, 100):
        if a % 10 == b / 10 and b % 10:
            result1 = float(a) / b
            result2 = float(a / 10) / (b % 10)
            if result1 == result2:
                print "%s / %s = %s" % (a, b, result1)

感想:

  1. 算出答案之后我觉得一定有很简单的数学方法来直接求出来
评论已关闭。
评论共