zoukankan      html  css  js  c++  java
  • (Problem 33)Digit canceling fractions

    The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/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 是一个奇怪的分数:当一个菜鸟数学家试图对其进行简化时,他可能会错误地可以认为通过将分子和分母上的9同时去除得到 49/98 = 4/8。但他得到的结果却是正确的。

    我们将30/50 = 3/5这样的分数作为普通个例。

    一共有四个这样的非普通分数,其值小于1,并且包括分子和分母都包括2位数。 如果将这四个分数的乘积约分到最简式,分母是多少?

    //(Problem 33)Digit canceling fractions
    // Completed on Thu, 25 Jul 2013, 17:47
    // Language: C
    //
    // 版权所有(C)acutus   (mail: acutus@126.com) 
    // 博客地址:http://www.cnblogs.com/acutus/
    
    #include<stdio.h>
    void swap(int *a, int *b)
    {
        int t;
        t=*a;
        *a=*b;
        *b=t;
    }
    
    int gcd(int a, int b)
    {
        int r;
        if (a < b)
            swap(&a,&b);
        if (!b)
            return a;
        while ((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
    
    void find()
    {
        int i;
        int M,N;
        M=N=1;
        for(i=12; i<50; i++)
        {
            for(int j=i+1; j<100; j++)
            {
                int t=gcd(i,j);
                if(t==1 || i/t>10 || j/t>10 || i%10!=j/10)
                    continue;
                else
                {
                    int a=i/10,b=j%10;
                    if(a/gcd(a,b)==i/t && b/gcd(a,b)==j/t)
                    {
                        M*=i/t;
                        N*=j/t;
                    }
                }
            }
        }
        printf("%d
    ",N/gcd(M,N));
    }
    
    int main()
    {
        find();
        return 0;
    }
    Answer:
    100
  • 相关阅读:
    Golang之redis
    Golang之Socket
    Golang之单元测试
    Golang之定时器,recover
    Python深度学习之安装theano(windows)
    电容充放电时间常数RC计算方法(转载)
    输入阻抗的理解(转载)
    浮点数的二进制表示
    modbus-poll和modbus-slave工具的学习使用——modbus协议功能码04的解析——04读输入寄存器
    STM32调试中遇到的工具困难(转载+整理)
  • 原文地址:https://www.cnblogs.com/acutus/p/3546606.html
Copyright © 2011-2022 走看看