Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Spyder Editor
- This is a temporary script file.
- """
- a,b=105,24
- while b > 0:
- a, b = b, a % b
- print(a)
- c,d=6024,1284
- while d > 0:
- c, d = d, c % d
- print(c)
- e,f=98777,12945
- while f > 0:
- e, f = f, e % f
- print(e)
- x,xprev,y,yprev=0,1,1,0
- g,h=105,24
- '''put in any positive integers for g and h with g>h'''
- while h > 0:
- q=float(g//h)
- g, h = h, g % h
- x, xprev = xprev - q * x, x
- y, yprev = yprev - q * y, y
- print(g,xprev,yprev)
- '''2C part(1)'''
- a,b=105,24
- '''put in any positive integers for a and b with a>b'''
- z=0
- while b > 0:
- a, b = b, a % b
- z=z+1
- print(a,z)
- #the z output is the number of steps in the euclid algorithm
- #2C part(2)-(5)
- from math import log
- from math import pi
- from math import e
- a,b=317811,196418
- '''put in any positive integers for a and b with a>b'''
- z=0
- maximum_z=5*log(a,10)
- average_z=(12/pi**2)*log(2,e)*log(a,e)
- while b > 0:
- a, b = b, a % b
- z=z+1
- print(z,maximum_z,average_z)
- '''a=105 and b=16 gives z=5 and z_aprrox=3.9221991448330873, this is an
- example the number of steps in the euclid algorithm being larger than the
- average. a=105 and b=21 gives z=1 and z_approx=3.9221991448330873, this
- is an example of the nuber of steps in the euclid algorithm being
- lower than the average number of steps.
- if you set a and b equal to the fibonacci numbers 317811 and 196418
- respectively, we get z = 26 and 27.51084462415267 '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement