Chinaunix首页 | 论坛 | 博客
  • 博客访问: 216266
  • 博文数量: 68
  • 博客积分: 3120
  • 博客等级: 中校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-08 09:53
文章分类
文章存档

2012年(29)

2011年(3)

2010年(18)

2009年(18)

我的朋友

分类: C/C++

2012-02-10 19:48:27

问题:

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.

答案:100

#include
using namespace std;

int main(){

    int numd1, numd2, dend1, dend2;

    for(int num = 10; num < 100; ++num){
        for(int den = 10; den < 100; ++den){
            if(num % 10 == 0 && den % 10 == 0)continue;
            if(num > den)continue;
            numd1 = num /10;
            numd2 = num % 10;
            dend1 = den / 10;
            dend2 = den % 10;
            if(numd1 + numd2 == dend1 + dend2)continue;

            if((numd1 == dend1 && (numd2 * den == num * dend2))
               || (numd1 == dend2 && (numd2 * den == num * dend1))
               || (numd2 == dend1 && (numd1 * den == num * dend2))
               || (numd2  == dend2 && (numd1 * den == num * dend1))
               )cout << num << "," << den << endl;
        }
    }
    return 0;
}


输出:
16,64 19,95 26,65 49,98

1/4×1/5×2/5×4/8=1/100


阅读(1027) | 评论(0) | 转发(0) |
0

上一篇:Project Euler Problem 32

下一篇:没有了

给主人留下些什么吧!~~