/
71.cpp
57 lines (46 loc) · 880 Bytes
/
71.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
56
#include <iostream>
#include <NTL/quad_float.h>
NTL_CLIENT
typedef struct {
int num;
int den;
} fract;
int MCD (int a, int b) {
while (b) {
int t=b;
b = a%b;
a=t;
}
return a;
}
bool cfactor (fract f) {
int a = f.num;
int b = f.den;
if (MCD(a,b)==1)
return false;
else
return true;
}
main() {
quad_float val = to_quad_float(3.0/7.0);
quad_float prec = to_quad_float(0.0);
fract my_f;
for (int i=999900; i<=1000000; i++) {
for (int j=1; j<i; j++) {
fract f;
f.num=j;
f.den=i;
if (
( (to_quad_float(to_quad_float(j) / to_quad_float(i))) >= prec) &&
( (to_quad_float(to_quad_float(j) / to_quad_float(i))) < val ) &&
(j!=3) && (i!=7)
) {
if (!cfactor(f)) {
my_f = f;
prec = to_quad_float(to_quad_float(j) / to_quad_float(i));
}
}
}
}
cout << my_f.num << "/" << my_f.den << endl;
}