-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path033.cpp
executable file
·55 lines (55 loc) · 1.07 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <sstream>
#define START 10
#define END 99
#define HOW_MANY_DIGITS 2
using namespace std;
string i2s(int i) {
stringstream ss;
ss << i;
return ss.str();
}
int s2i(string s) {
stringstream ss(s);
int i;
ss >> i;
return i;
}
void convert(int &a, int &b) {
string x = i2s(a);
string y = i2s(b);
for (int i = 0; i < HOW_MANY_DIGITS; i++) {
for (int j = 0; j < HOW_MANY_DIGITS; j++) {
if (x[i] == y[j] && x[i] != '0') {
x.erase(i, 1);
y.erase(j, 1);
a = s2i(x);
b = s2i(y);
return;
}
}
}
}
int gcd(int a, int b) {
while (a != b) {
if (a > b) a -= b;
else if (b > a) b -= a;
}
return a;
}
int main() {
int productNumerators = 1;
int productDenumerators = 1;
for (int d = START; d <= END; d++) {
for (int n = START; n < d; n++) {
int d2 = d;
int n2 = n;
convert(d2, n2);
if ((float) n / d == (float) n2 / d2 && n != n2) {
productNumerators *= n;
productDenumerators *= d;
}
}
}
cout << productDenumerators / gcd(productNumerators, productDenumerators) << endl;
}