Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #sage
- def fraction(x):
- result=[]
- while 1:
- if (x==int(x)):
- result.append(int(x))
- break
- result.append(int(x))
- x=1/(x-int(x))
- return result
- def convergent(a,dmax):
- result=[]
- result.append([a[0],1])
- result.append([a[0]*a[1]+1,a[1]])
- for i in range(2,len(a)):
- p=a[i]*result[i-1][0]+result[i-2][0]
- q=a[i]*result[i-1][1]+result[i-2][1]
- if q>dmax:
- break
- result.append([p,q])
- if a[0]==0:
- result.pop(0)
- return result
- def check(k,d,e,n):
- phi=(e*d-1)/k
- if int(phi)!=phi:
- print "No! Error phi"
- return 0
- b=n-phi+1
- delta=b**2-4*n
- can_delta=sqrt(delta)
- if int(can_delta)!=can_delta:
- print "No! Error delta"
- return 0
- else:
- print (b+can_delta)/2,(b-can_delta)/2
- def wiener(e,n):
- dmax=pow(n,1/4)/3
- a=convergent(fraction(e/n),dmax)
- for i in range(len(a)):
- check(a[i][0],a[i][1],e,n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement