Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor
  4.  
  5. This is a temporary script file.
  6. """
  7. a,b=105,24
  8.  
  9. while b > 0:
  10. a, b = b, a % b
  11. print(a)
  12.  
  13. c,d=6024,1284
  14.  
  15. while d > 0:
  16. c, d = d, c % d
  17. print(c)
  18.  
  19. e,f=98777,12945
  20.  
  21. while f > 0:
  22. e, f = f, e % f
  23. print(e)
  24.  
  25. x,xprev,y,yprev=0,1,1,0
  26. g,h=105,24
  27. '''put in any positive integers for g and h with g>h'''
  28. while h > 0:
  29. q=float(g//h)
  30. g, h = h, g % h
  31. x, xprev = xprev - q * x, x
  32. y, yprev = yprev - q * y, y
  33. print(g,xprev,yprev)
  34.  
  35. '''2C part(1)'''
  36. a,b=105,24
  37. '''put in any positive integers for a and b with a>b'''
  38. z=0
  39. while b > 0:
  40. a, b = b, a % b
  41. z=z+1
  42. print(a,z)
  43. #the z output is the number of steps in the euclid algorithm
  44.  
  45. #2C part(2)-(5)
  46. from math import log
  47. from math import pi
  48. from math import e
  49. a,b=317811,196418
  50. '''put in any positive integers for a and b with a>b'''
  51. z=0
  52. maximum_z=5*log(a,10)
  53. average_z=(12/pi**2)*log(2,e)*log(a,e)
  54. while b > 0:
  55. a, b = b, a % b
  56. z=z+1
  57. print(z,maximum_z,average_z)
  58. '''a=105 and b=16 gives z=5 and z_aprrox=3.9221991448330873, this is an
  59. example the number of steps in the euclid algorithm being larger than the
  60. average. a=105 and b=21 gives z=1 and z_approx=3.9221991448330873, this
  61. is an example of the nuber of steps in the euclid algorithm being
  62. lower than the average number of steps.
  63. if you set a and b equal to the fibonacci numbers 317811 and 196418
  64. respectively, we get z = 26 and 27.51084462415267 '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement