Пример #1
0
def main(n):
    """
    Find the nth prime number
  """
    i = 2
    counter = 0
    while True:
        if isPrime(i):
            counter += 1
            if counter == n:
                print i
                break
        i += 1
Пример #2
0
def slow(n):
  '''
    Find the sum of all primes below n.
    Slow method, checking every value
    for primacy and summing.
  '''
  i = 2
  sum = 0
  while i < n:
    if isPrime(i):
      sum += i
    
    i+= 1 
  print sum
Пример #3
0
def main(n):
  '''
    Find the smallest number evenly divisble
    by all numbers from 1 to n
  '''
  prod = 1
  factors = {}
  for i in range(2, n+1):
    for j in range(2,i):
      print i,j
      if isPrime(j):
        if j not in factors.keys():
          factors[j] = 1
        else:
          factors[j] += i//j - factors[j]
  print factors

  for i in factors.keys():
    prod *= i ** factors[i]
  #prod *= i
  print prod