tonybaldwin

prime log ratio thingy

Sep 4th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Problem Set 1
  4. # Name: Tony Baldwin
  5. # Collaborators: 0
  6. # Time: (start 4pm Sat 20110903 / end ??)
  7.  
  8. from math import *
  9.  
  10. n = input("Please enter a number: ")
  11. primes = [2]
  12. logs = [0.301029995664]
  13. q = 3
  14. while q < n:
  15.     for i in primes:
  16.         if q % i == 0:
  17.             break
  18.     else:
  19.         l = log10(q)
  20.         primes.append(q)
  21.         logs.append(l)
  22.     q += 2
  23.  
  24. slog = reduce(lambda y,x: x+y, logs)
  25. print("The sum of the logs of the prime numbers less than or equal to %s is %s." % (n, slog))
  26. rat =(slog / n)
  27. print("The ratio of these values is %s / %s, which is equal to %s." % (slog, n, rat))
  28. print("Have a nice day.")
  29. exit
Advertisement
Add Comment
Please, Sign In to add comment