Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. __author__ = 'behemothh'
  2. def my_func(a):
  3. s = 0
  4. k = 0
  5. while k < (a**3):
  6. k += 1
  7. s += k
  8. return s
  9.  
  10.  
  11. import time
  12.  
  13. for test_value in [10, 50, 100, 150, 200, 250]:
  14.  
  15. s = my_func(test_value)
  16. print s,"dette er s"
  17.  
  18. print "my_func() with value = {} took {:.2f} milliseconds"
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. def primes(n):
  26. t0 = time.time()
  27.  
  28. primfac = []
  29. d = 2
  30. while d*d <= n:
  31. while (n % d) == 0:
  32. primfac.append(d) # supposing you want multiple factors repeated
  33. n //= d
  34. d += 1
  35. if n > 1:
  36. primfac.append(n)
  37. t1 = time.time()
  38.  
  39. return primfac,"Dette tok ",(t1-t0)*1000.0," millisekunder"
  40.  
  41.  
  42.  
  43. print "a) ",primes(438972993803)
  44. print "b) ",primes(24231186386293)
  45. print "c) ",primes(6446424082262063)
  46. print "d) ",primes(2532386475205751977)
  47. print "e) ",primes(607668475597090743973)
  48. print "f) ",primes(434220334639935732838391193782579654449762442496152115147965940029674236149760)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement