def get_nth(n):
  ''' This will print out n primes '''
  p = pyprimes.nprimes(n)
  p_list = []
  for prime in p:
    p_list.append(prime)
  for prime in p_list:
    if not prime == p_list[-1]:
      print str(prime) + ',',
    else:
      print p_list[-1]
Beispiel #2
0
def get_nth(n):
    ''' This will print out n primes '''
    p = pyprimes.nprimes(n)
    p_list = []
    for prime in p:
        p_list.append(prime)
    for prime in p_list:
        if not prime == p_list[-1]:
            print str(prime) + ',',
        else:
            print p_list[-1]
def generate_keypair():
	primes =list(pyprimes.nprimes(10000))
	first_index = random.randrange(0, len(primes))
	second_index = random.randrange(0, len(primes))
	if second_index == first_index:
		second_index = second_index + 1
	p = primes[first_index]
	q = primes[second_index]
	K = p * q
	e = 65537
	phi = (p-1) * (q-1)
	k = inverse(e, phi)
	return ((e, K), (k, K))
Beispiel #4
0
def concat_n_primes(n):
    """
    concat_n_primes(n) -> int(number)
    
    Concatenating the first n primes from zero into a number.

    :@param     n(int) - An index number.
    :@return    concat_n_primes(int) - A number formed by concatenating 
                                       the n first primes.
    """

    # Verbose.
    print("Concatenating first {0} primes together".format(n))

    # Initialize.
    num_len = 0
    result = Mod(0, MOD)

    # Concatenating the first n primes.
    for prime_num in pyprimes.nprimes(n):
        result += prime_num
        num_len += len(str(prime_num))

    return result, num_len
Beispiel #5
0
import sys
import pyprimes

arg = int(sys.argv[1])

p = pyprimes.nprimes(arg)
ans = 0
for i in p:
    ans = i
print('Answer: ', ans)
Beispiel #6
0
from random import randint
from pyprimes import nprimes

N = 32
J = 500

jamcoins = set()
somePrimes = list(nprimes(47))[1:]


def findDiv(val):
    for p in somePrimes:
        if val % p == 0: return p
    return None


def getDivisors(coin):
    divs = []
    for base in range(2, 11):
        val = int(coin, base)
        div = findDiv(val)
        if not div: return None
        divs.append(div)
    return tuple(divs)


while len(jamcoins) < J:
    coin = ''
    for i in range(N - 2):
        coin += str(randint(0, 1))
    coin = '1' + coin + '1'
Beispiel #7
0
 def test_nprimes(self):
     it = pyprimes.nprimes(100)
     self.assertTrue(it is iter(it))
     self.assertEqual(list(it), PRIMES)
Beispiel #8
0
 def test_nprimes(self):
     it = pyprimes.nprimes(100)
     self.assertTrue(it is iter(it))
     self.assertEqual(list(it), PRIMES)
def main():
    primes = list(nprimes(10001))
    print primes[10000]
Beispiel #10
0
from pyprimes import nprimes
from functools import reduce

primelist = list(nprimes(1000001))  # [2, 3, 5, ...]


def primorial(n):
    return reduce(int.__mul__, primelist[:n], 1)


if __name__ == '__main__':
    print('First ten primorals:', [primorial(n) for n in range(10)])
    for e in range(7):
        n = 10**e
        print('primorial(%i) has %i digits' % (n, len(str(primorial(n)))))
Beispiel #11
0
def prime_generator():
    return pyprimes.nprimes(2000)
Beispiel #12
0
def prime_generator():
	return pyprimes.nprimes(2000)
Beispiel #13
0
#!/usr/bin/python

from pyprimes import nprimes

primos = list(nprimes(1000000))

print "int primos[] = {"

for p in primos:
    print "%d, " % p,

print "};\n"
Beispiel #14
0
from multiprocessing import Process, Queue
import hashlib
import sys
import os
import warnings

if sys.version_info < (3, 6):
    import sha3

# Python 2.7 compatibility
try:
    range = xrange
except NameError:
    pass

prime_list = list(nprimes(30))


def _first_prime_check(p):
    for prime in prime_list:
        if p % prime == 0:
            return False
    return True


def _multiplicative_inverse(num, modulo):
    """
    Return the multiplicative inverse of the given number in given modulo or raises a ValueError if no inverse exists.
    :param num: Number to be inverted
    :type num: int
    :param modulo: