Example #1
0
def main():
    n = int(argv[1])

    if is_prime(n, 25):
        print('{} - простое'.format(n))
        return

    with open('p.txt') as f:
        primes_data = f.read()
    primes = list(map(int, primes_data.split('\n')))

    if '-u' in argv:
        p = dixon(n, primes, dixon_usual)
        assert n % p == 0
        print('Стандартный алгоритм:\n{} * {}'.format(p, n // p)) \
            if p != -1 else print('Делитель не найден')
    if '-m' in argv:
        p = dixon(n, primes, dixon_modified)
        assert n % p == 0
        print('С добавлением -1 и выбором наименьшего а:\n{} * {}'.format(p, n // p)) \
            if p != -1 else print('Делитель не найден')
    if '-c' in argv:
        p = dixon(n, primes, dixon_chain)
        assert n % p == 0
        print('С использованием цепных дробей:\n{} * {}'.format(p, n // p)) \
            if p != -1 else print('Делитель не найден')
Example #2
0
File: p003b.py Project: nunoi/euler
def PollardRho(n):
  i = 1
  x = random.randint(0, n - 1)
  y = x
  k = 2
  tried = set()
  tried.add(x)
  while True:
    i = i + 1
    x = (x ** 2 - 1) % n
    if x in tried:
      return
    tried.add(x)
    d = Euclid(y - x, n)
    if d != 1 and d != n:
      if mutils.is_prime(d):
        print d
#      print str(d) + " - " + str(is_prime(int(d))) # d is a factor. Print it.
    if i == k:
      y = x
      k = 2 * k
Example #3
0
File: p010.py Project: nunoi/euler
#!/usr/bin/python

import sys
import mutils

# Sieve approach
sum = 0
# problem was changed from 1.000.000 to 2.000.000
# primeList = mutils.prime_sieve(1000000)
primeList = mutils.prime_sieve(2000000)
for i in primeList:
	sum = sum + i
print sum
sys.exit(0)

# Brute force approach
# This is too slow - it takes around 150s (2.5 mins) in an Athlon XP 2600
sum = 2
# 1.000.000 is multiple of ten so we can end the checking at 999.999
for i in range(3, 1000000, 2):
	if mutils.is_prime(i):
		sum = sum + i
print sum

Example #4
0
File: p007.py Project: nunoi/euler
#!/usr/bin/python

import sys
import mutils

# i is the accumulated number of primes
i = 2
# n is the number to be tested
n = 3 

while i != 10001:
	n = n + 2
	if mutils.is_prime(n):
		i = i + 1
#		print i
print "The 10001st prime is: " + str(n)