-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem71.h
More file actions
36 lines (30 loc) · 886 Bytes
/
problem71.h
File metadata and controls
36 lines (30 loc) · 886 Bytes
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
//
// Created by Karun Ram, Pratim Chowdhary on 4/21/22.
//
#ifndef PROJECT_EULER_PROBLEM71_H
#define PROJECT_EULER_PROBLEM71_H
#include "cmath"
#include "../include/print_lib.h"
using namespace std;
void find_closest_fraction(int* frac, int d, double target) {
double closest = 1;
for (int i = 1; i <= d; i++) {
for (int j = frac[0]; j < i; j++) {
double val = (double) j / i;
if (val > target) break;
if (target - val > 0 and target - val < closest) {
frac[0] = j;
frac[1] = i;
closest = target - val;
}
}
}
}
void problem_71_solution(bool log) {
double target = 3.0 / 7;
int d = 1000000;
int fraction[2] = {0, 0};
find_closest_fraction(fraction, d, target);
if (log) cout << fraction[0] << endl;
}
#endif //PROJECT_EULER_PROBLEM71_H