-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem 33
More file actions
53 lines (44 loc) · 1.76 KB
/
Copy pathproblem 33
File metadata and controls
53 lines (44 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
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.
*/
#include <iostream>
using namespace std;
void same_digit(int numerator, int denominator){
// how much real division is equal then slice numbers
double divisor = static_cast<double>(numerator) / static_cast<double>(denominator);
int first_numerator = numerator % 10;
int second_numerator = (numerator % 100 - first_numerator) / 10;
int first_denominator = denominator % 10;
int second_denominator = (denominator % 100 - first_denominator) / 10;
// first case
if (first_numerator == second_denominator){
double x = denominator % 10;
double solution = static_cast<double>((numerator / 10)) / x;
if (solution == divisor && solution < 1){
cout <<numerator << " : " << denominator << " : " << solution <<endl;
}
}
//second case
if(second_numerator == first_denominator){
double y = numerator % 10;
double solution = y / static_cast<double>((denominator / 10));
if (solution == divisor && solution < 1){
cout <<numerator << " : " << denominator << " : " << solution <<endl;
}
}
}
int main() {
for(int i = 10; i < 100; i++){
for(int j = i + 1; j < 100; j++){
if(i % 10 == 0 || j % 10 == 0){
}
else{
same_digit(i, j);
}
}
}
return 0;
}