-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33.cpp
More file actions
70 lines (51 loc) · 1.67 KB
/
Copy path33.cpp
File metadata and controls
70 lines (51 loc) · 1.67 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
vi list_digits(int n) {
vi res;
while(n != 0) {
res.push_back(n % 10);
n /= 10;
}
reverse(res.begin(), res.end());
return res;
}
int main() {
int hasil_pembilang = 1;
int hasil_penyebut = 1;
for(int i = 12; i < 99; i++) {
for(int j = i + 1; j < 99; j++) {
if(i % 10 == 0 || j % 10 == 0) continue;
if(i % 11 == 0 || j % 11 == 0) continue;
int pembilang = i;
int penyebut = j;
vi digit_pembilang = list_digits(pembilang);
vi digit_penyebut = list_digits(penyebut);
int jumlah_sama = 0;
int idx_sama_pembilang, idx_sama_penyebut;
for(int k = 0; k < 2; k++) {
for(int l = 0; l < 2; l++) {
if(digit_pembilang[k] == digit_penyebut[l]) {
jumlah_sama++;
idx_sama_pembilang = k;
idx_sama_penyebut = l;
}
}
}
if(jumlah_sama != 1) continue;
int pembilang_akhir = digit_pembilang[1 - idx_sama_pembilang];
int penyebut_akhir = digit_penyebut[1 - idx_sama_penyebut];
if(pembilang * penyebut_akhir == penyebut * pembilang_akhir) {
hasil_pembilang *= pembilang;
hasil_penyebut *= penyebut;
}
}
}
int fpb = gcd(hasil_pembilang, hasil_penyebut);
if(fpb != 1) {
hasil_pembilang /= fpb;
hasil_penyebut /= fpb;
}
cout << hasil_pembilang << ' ' << hasil_penyebut;
return 0;
}