-
Notifications
You must be signed in to change notification settings - Fork 0
/
033.cpp
43 lines (37 loc) · 804 Bytes
/
033.cpp
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
/****
* Problem 33 - Digit canceling fractions
*/
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
int gcd(int a, int b)
{
while (b != 0)
{
int t = b;
b = a % b;
a = t;
}
return a;
}
int main()
{
int g_d = 1;
int g_n = 1;
for (int i = 9; i > 2; i--)
for (int d = i-1; d > 1; d--)
for (int n = i-1; n > 0; n--)
if (9 * n * (d - i) == i * (n - d))
{
g_n *= n;
g_d *= d;
}
cout << " " << g_n << endl;
cout << "The product is ----- = " << (g_d / gcd(g_n, g_d))<< endl;
cout << " " << g_d << endl;
return 0;
}