Advertisement
ebx

Proracun sume 1/n

ebx
Nov 5th, 2012
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def primeFactors(n):
  2.     factors = []
  3.     lastresult = n
  4.     while 1:
  5.         if lastresult == 1:
  6.             break
  7.  
  8.         c = 2
  9.  
  10.         while 1:
  11.             if lastresult % c == 0:
  12.                 break
  13.  
  14.             c += 1
  15.  
  16.         factors.append(c)
  17.         lastresult /= c
  18.  
  19.     return factors
  20.  
  21. def run(n):
  22.     bad = []
  23.     sum = 0.0
  24.  
  25.     for i in range(30, n, 30):
  26.         li = primeFactors(i)
  27.         for el in li:
  28.             if (el != 2) and (el != 3) and (el != 5):
  29.                 bad.append(i)
  30.            
  31.     for i in range(30, n, 30):
  32.         if i not in bad:
  33.             sum += 1.0/i
  34.        
  35.     return sum
  36.  
  37. # run(10000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement