Example #1
0
def a(n):
    m=n**0.5
    x=[1]
    y=[1]
    z=[int(m)]
    ss=[int(m)]
    i=0
    while True:
        t1=(x[i]**2)*n-z[i]**2
        s=divisor(t1,y[i])
        t1=t1//s
        t2=int((y[i]*x[i])//s)
        t3=int((y[i]*z[i])//s)
        s2=int((t2*m+t3)//t1)
        ss.append(s2)
        for j in range(len(x)):
            if t1==y[j] and t2==x[j] and s2*t1-t3==z[j]:
                return ((len(x)-j)&1==1)
        y.append(t1)
        z.append(s2*t1-t3)
        x.append(t2)
        i=i+1
Example #2
0
def f(n):
    m=n**0.5
    x=[]
    y=[1]
    z=[int(m)]
    ss=[]
    p,q=1,int(m)
    i=0
    while True:
        t1=n-q**2
        s=divisor(t1,p)
        t1=t1//s
        t3=int((p*q)//s)
        s2=int((m+t3)//t1)
##        print(p,q,s,t1,t3,ss)
        ss.append(s2)
        p,q=t1,s2*t1-t3
        if s2==2*int(m):
##            print(s2,ss)
            break
        i=i+1
    return (int(m),ss)