I have an idea for my old problem was mentioned hereFRACTIONS. I saw one relationship between it and another one so I tried to optimize that given problem by similar method. For example,
$$\frac{1}{6}\rightarrow \frac{2}{7}\rightarrow \frac{3}{8}\rightarrow \frac{4}{9}\rightarrow \frac{5}{10}:=\frac{1}{2}\rightarrow \frac{2}{3}$$
I observe $$\frac{2}{3}= \frac{1}{1+ \frac{1}{2}}$$ $$\frac{1}{6}= \frac{1}{2\cdot 3}\rightarrow \frac{1}{2}$$ Because $\dfrac{1}{a}$ is always in the desired form, and what we need to do is finding $\dfrac{1}{a}\rightarrow \dfrac{1}{b}$ by the greatest divisor of $6$ is $3.$ This way is useful to create lowest terms with continued-fractions.
Another example: $$\frac{2}{3}\rightarrow \frac{3}{4}\rightarrow \cdots \rightarrow \frac{11}{14}\neq \frac{11}{15}$$ Because $$\frac{11}{15}= \frac{1}{1+ \frac{1}{2+ \frac{1}{1+ \frac{1}{3}}}}$$ and $$\frac{1}{6}< \frac{1}{3}< \frac{1}{2}$$ And for complex counter-example: $$\frac{2}{3}\rightarrow \frac{25}{26}\neq \frac{25}{34}= \frac{1}{1+ \frac{1}{2+ \frac{1}{1+ \frac{1}{3+ \frac{1}{2}}}}}$$ On the other hand, seems like it involving toRATCONVERT, I can't do it, at least, I completed the algorithm, I will show you in the environment C++:
#include <iostream>
#include <math.h>
using namespace std;
int main() {
long long k, m, q;
cin>>k>>m;
long long r1=m, r2=k;
int v1=0, v2=1;
while (true) {
if (v2>=sqrt(m/2)) {
cout<<0<<", "<<0;
break;
}
else {
if (r2<sqrt(m/2)) {
cout<<v2/sqrt(v2*v2)*r2<<", "<<sqrt(v2*v2);
break;
}
else {
q=round(r1/r2);
r1=r1-q*r2;
v1=v1-q*v2;
swap(r1, r2);
swap(v1, v2);
}
}
}
}
So $u= \dfrac{Kv- r}{M}$ satisfied the conditions, how to change it to solve this problem, I need to the help, very much thank you.