Пример #1
0
def table_doubling():
    global table, size, collisions, occupied
    collisions = 0
    occupied = 0
    tmp = table
    size = next_prime(size * 2)
    table = size * [None]
    for trans in tmp:
        if trans is not None:
            insert(trans)
Пример #2
0
def compute_k(b: int) -> int:

    k = 1

    cur_prime = 2

    while cur_prime <= b:

        cur_expo = 1

        while cur_prime ** cur_expo <= b:
            k *= cur_prime
            cur_expo += 1

        cur_prime = next_prime(cur_prime)

    return k
Пример #3
0
def main(lt):
    MAX_SIZE = 0
    MAX_VAL = None
    L = [2]
    beg = 0
    while True:
        end = beg
        SUM = L[beg]
        if SUM >= lt:
            break
        while True:
            end += 1
            if end == len(L):
                L.append(prime.next_prime(L[-1]))
            SUM += L[end]
            if SUM >= lt:
                break
            if prime.is_prime(SUM) and end - beg + 1 > MAX_SIZE:
                MAX_SIZE = end - beg + 1
                MAX_VAL = SUM
        if end - beg <= MAX_SIZE:
            break
        beg += 1
    return MAX_VAL
Пример #4
0
	def test_nextany_negative_is2(self):
		self.assertEqual(prime.next_prime(-540), 2, msg = "The least prime number is 2!")
Пример #5
0
	def test_nextprime_seven_iseleven(self):
		self.assertEqual(prime.next_prime(7), 11)
Пример #6
0
 def test_next_prime(self):
     self.assertEqual(next_prime(5), 7)
Пример #7
0
from prime import next_prime
from generator import generate_input

n = 1000000
collisions = 0
size = next_prime(1000)
p = next_prime(62)
table = size * [None]
load_factor = 0.0
occupied = 0
visited = []
res = []
daysVisit = 7 * [0]
daysMap = {
    0: 'Monday',
    1: 'Tuesday',
    2: 'Wednesday',
    3: 'Thursday',
    4: 'Friday',
    5: 'Saturday',
    6: 'Sunday',
}


def hash(card, m):
    value = 0
    for i, letter in enumerate(card):
        value = value + ord(letter) * (p**i)
    return value % m

Пример #8
0
def main(num):
    x = 1
    for i in range(num):
        x = prime.next_prime(x)
    return x
Пример #9
0
from utils import ask_yes_no_cmd
from prime import next_prime
import time

parser = ArgumentParser()
parser.add_argument("-n",
                    "--number",
                    type=int,
                    help="Number to start from",
                    default=0)
args = parser.parse_args()

current_prime = args.number
while True:
    start_time = time.time_ns()
    current_prime = next_prime(current_prime)
    end_time = time.time_ns()

    print(f"Prime is: {str(current_prime)}")

    exec_time = {
        "s": (end_time - start_time) // 1000000000,
        "ms": ((end_time - start_time) -
               (end_time - start_time) // 1000000000) / 1000000
    }
    print("Execution time: {:.0f}s {:.3f}ms".format(exec_time['s'],
                                                    exec_time['ms']))

    if not ask_yes_no_cmd("Find next prime?"):
        break
Пример #10
0
def main(num):
    x = 1
    for i in range(num):
        x = prime.next_prime(x)
    return x
Пример #11
0
from prime import next_prime
import time


def is_prime(x):
    if x < 2:
        return True
    for i in range(2, x):
        if x%i == 0:
            return False
    return True

def py_next_prime(x):
    while not is_prime(x):
        x += 1
    return x


test_val = 1000000004

# pybind
start = time.time()
print('The next prime after/including {} is : {}'.format(test_val, next_prime(test_val)))
print('Pybind function used {} seconds'.format(time.time()-start))

# python
start = time.time()
print('The next prime after/including {} is : {}'.format(test_val, py_next_prime(test_val)))
print('Python function used {} seconds'.format(time.time()-start))
Пример #12
0
def main(num):
    x = 1
    while True:
        x = next_prime(x)
        if prime_family(x, num):
            return x
Пример #13
0
def main(num):
    x = 1
    while True:
        x = next_prime(x)
        if prime_family(x, num):
            return x