コード例 #1
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]
コード例 #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]
コード例 #3
0
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))
コード例 #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
コード例 #5
0
ファイル: euler07.py プロジェクト: FausticSun/FausticEuler
import sys
import pyprimes

arg = int(sys.argv[1])

p = pyprimes.nprimes(arg)
ans = 0
for i in p:
    ans = i
print('Answer: ', ans)
コード例 #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'
コード例 #7
0
ファイル: tests.py プロジェクト: uzumaxy/pyprimes
 def test_nprimes(self):
     it = pyprimes.nprimes(100)
     self.assertTrue(it is iter(it))
     self.assertEqual(list(it), PRIMES)
コード例 #8
0
ファイル: tests.py プロジェクト: cesarfm/pyprimes
 def test_nprimes(self):
     it = pyprimes.nprimes(100)
     self.assertTrue(it is iter(it))
     self.assertEqual(list(it), PRIMES)
コード例 #9
0
def main():
    primes = list(nprimes(10001))
    print primes[10000]
コード例 #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)))))
コード例 #11
0
ファイル: 61.py プロジェクト: luceatnobis/challenges
def prime_generator():
    return pyprimes.nprimes(2000)
コード例 #12
0
def prime_generator():
	return pyprimes.nprimes(2000)
コード例 #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"
コード例 #14
0
ファイル: DSA.py プロジェクト: cryptobuks1/crycur
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: