class Main:
def __init__(self,depth):
self.v = [i * 0 for i in range(1001)];
self.ans = [i * 0 for i in range(1001)];
self.ans[0]=0;
self.depth = depth;
self.ans[depth]=0x3fffff;
self.flag = False;
def gcd(self,a, b):
if b == 0:
return a
else:
return self.gcd(b, a % b)
def handleProblem(self,b,a,n):
if n==self.depth:
if a%b:
return;
if a//b==self.v[n-1]: return;
self.v[n]=a//b;
cmp=0;
i = n+1;
self.flag=True
while True:
if i<=0:
break;
i -= 1;
if self.ans[i]==self.v[i]: continue;
if self.ans[i]<self.v[i]: continue;
else:
cmp=1;
break;
if cmp==1:
for i in range(1,n+1):
self.ans[i]=self.v[i];
return;
else:
i = max((a + 1) // b + 1, self.v[n - 1] + 1);
while True:
if (self.depth-n+1)*a < b*i: break;
self.v[n]=i;
x1=a*i;
x2=b*i-a;
c=self.gcd(x1,x2);
x1=x1//c;
x2=x2//c;
i += 1;
self.handleProblem(x2,x1,n+1);
handle=Main(2)
b = int(input('请输入分子').strip())
a=int(input('请输入分母').strip());
if a%b==0:
print(b,a)
else:
x=handle.gcd(b,a);
b=b//x;
a=a//x;
while True:
handle.handleProblem(b,a,1)
if handle.flag:
break;
handle.depth=handle.depth+1;
print(handle.ans[1:handle.depth+1])
大佬们哪里出错了呢