-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollatzSolver.cpp
More file actions
56 lines (48 loc) · 827 Bytes
/
Copy pathCollatzSolver.cpp
File metadata and controls
56 lines (48 loc) · 827 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <tuple>
#include <chrono>
#include <numeric>
void solve(int A, int B, int *result)
{
if (A == 0)
{
result[0] = 0;
result[1] = 1;
return;
}
int xy[2];
solve(B % A, A, xy);
result[0] = (xy[1] - (B / A) * xy[0]);
result[1] = xy[0];
}
void diophantSolution(int A, int B, int C, int *result)
{
int coeff0 = 1;
int coeff1 = 1;
if (A < 0)
{
coeff0 = -1;
A = abs(A);
}
if (B < 0)
{
coeff1 = -1;
B = abs(B);
}
int solution[2];
solve(A, B, solution);
result[0] = coeff0 * (solution[0] - (solution[0] / B) * B);
result[1] = coeff1 * (solution[1] - (solution[1] / A) * A);
// return [solution[i] - (solution[i]/[B, A][i])*[B, A][i] for i in range(len(solution))]
}
class DiophantSolver
{
public:
void operator()(int a, int b, int c)
{
}
};
int main()
{
return 0;
}