您的位置:首页
Project Euler:Problem 33 Digit cancelling fractions
2017-06-03 10:04
561 查看
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.
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.
#include <iostream> using namespace std; int gcd(int a, int b) { while (b) { if (a < b) { int tmp = b; b = a; a = tmp; } int t = b; b = a % b; a = t; } return a; } int main() { int fz = 1; int fm = 1; int res; for (int x = 10; x <= 98; x++) { for (int y = x + 1; y <= 99; y++) { int a = x / 10; int b = x % 10; int c = y / 10; int d = y % 10; if ((b - c) == 0 && (y*a == x*d) && (d != 0)) { fz *= a; fm *= d; } } } res = fm / gcd(fz, fm); cout << res << endl; system("pause"); return 0; }
相关文章推荐
- Project Euler:Problem 33 Digit cancelling fractions
- Problem 33 Digit cancelling fractions (暴力set+pair)
- project euler 33 Digit cancelling fractions
- (Problem 33)Digit canceling fractions
- (Problem 33)Digit canceling fractions
- projecteuler---->problem=33----Digit canceling fractions
- (Problem 33)Digit canceling fractions
- Project Euler:Problem 90 Cube digit pairs
- PE 033 Digit cancelling fractions
- Project Euler:Problem 51 Prime digit replacements
- NO33_Digit canceling fractions
- Project Euler:Problem 73 Counting fractions in a range
- Project Euler:Problem 30 Digit fifth powers
- Project Euler:Problem 34 Digit factorials
- Project Euler:Problem 74 Digit factorial chains
- Digit cancelling fractions
- 欧拉工程第33题:Digit cancelling fractions
- Project Euler:Problem 16 Power digit sum
- Project Euler:Problem 92 Square digit chains
- Project Euler:Problem 25 1000-digit Fibonacci number