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,是一种例子。
这种类型的分数恰好有四个非平凡的因子,小于一个值,并且在分子和分母中包含两个数字。
如果这四个分数的乘积以其最低公共项给出,请找到分母的值。
#### 思路
这道题很简单啦~~
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,是一种例子。
这种类型的分数恰好有四个非平凡的因子,小于一个值,并且在分子和分母中包含两个数字。
如果这四个分数的乘积以其最低公共项给出,请找到分母的值。
#### 思路
这道题很简单啦~~
记得m/n = a / b,可以换成乘法公式m * b = n * a;
#include <stdio.h>
int gcd(int a, int b){
if(!b) return a;
return gcd(b, a % b);
}
int Isfraction(int x, int y){
if(x > 100 || x < 10) return 0;
if(y > 100 || y < 10) return 0;
int x1 = x / 10;
int x2 = x % 10;
int y1 = y / 10;
int y2 = y % 10;
if(!x1 || !x2 || !y1 || !y2) return 0;
if(x1 == y1 && x2 * y == y2 * x && x2 != 0) return 1;
if(x2 == y2 && x1 * y == y1 * x && x1 != 0) return 1;
if(x1 == y2 && x2 * y == y1 * x && x1 != 0) return 1;
if(x2 == y1 && x1 * y == y2 * x && x2 != 0) return 1;
return 0;
}
int main(){
int x = 1, y = 1, c;
for(int i = 10; i <= 100; i++){
for(int j = i + 1; j <= 100; j++){
if(Isfraction(i, j) == 0) continue;
x *= i; y *= j;
c = gcd(x,y);
x /= c;
y /= c;
}
}
printf("%d\n",y);
return 0;
}