예제 #1
0
def solve(start, end, required_results):
    primes = primesieve.generate_n_primes(0x10000)
    results = []
    x = start  # 0b10000000000000000000000000000001
    while x < end:  # 0b100000000000000000000000000000000:
        deviders = []
        str_x = bin(x)[2:]
        for b in range(2, 11):
            x_in_base = int(str_x, b)
            half_x = x_in_base >> 1
            devider = 1
            for p in primes:
                if p > half_x:
                    break
                if 0 == x_in_base % p:
                    devider = p
                    break
            if 1 == devider:
                break
            deviders.append(devider)
        else:
            results.append(
                "%s %s" %
                (str_x, ' '.join([str(devider)
                                  for devider in deviders]).strip()))
            if len(results) >= required_results:
                break
        x += 2
    return results
예제 #2
0
def largest_factor(num, number_of_spokes = 3):

    spokes = generate_n_primes(n)
    wheel = reduce(lambda x, y: x * y, spokes)
    composites = []
    for i in range(1, wheel):
        if all( i % k != 0 for k in spokes):
            composites.append(i)

    for factor in spokes:
        if num % factor == 0 and n > factor:
            num //= factor
            while num % factor == 0:
                num //= factor
            if num == 1:
                return factor

    multiple = 0
    limit = num**0.5
    while factor < limit:
        for step in composites:
            factor = multiple + step
            if num % factor == 0 and factor > 1:
                num //= factor
                while num % factor == 0:
                    num //= factor
                if num == 1: return factor
                limit = num**0.5
        multiple += wheel
    return num
예제 #3
0
def solve(k, modulus=None):
    """Calculate the smallest number with 2**k divisors."""
    n = 1

    costs = primesieve.generate_n_primes(k)  # more than necessary

    for i in range(k):
        cost = heapq.heappop(costs)
        heapq.heappush(costs, cost**2)
        n *= cost
        if modulus:
            n %= modulus

    return n
예제 #4
0
    def compute_provisional_chunks(self, start_value, nvalues, nchunks, save_opts):
        logger.info("computing provisional chunks, starting from {}".format(start_value))
        next_prime = primesieve.generate_n_primes(1, start_value)
        logger.info("next_prime for start_value={} is {}".format(start_value, next_prime))
        m6_start = next_prime[0] % 6
        logger.info("m6_start is {}".format(m6_start))
        if m6_start == 1:
            logger.info("m6_start is {}, so using start_pos = 0".format(m6_start))
            prime_start_pos = 0
        else:
            logger.info("m6_start is {}, so using start_pos = 5".format(m6_start))
            prime_start_pos = 5

        linkedValues = HexValues(1, prime_start_pos, 1, 0)  # magic starting "previous" values
        end_value = start_value + nvalues
        hfile = compute_hex_positions(start_value, end_value, linkedValues, save_opts)
        logger.info("save info: {}".format(save_opts))
        self.compute_next_chunks(hfile, nvalues, nchunks - 1, save_opts)
예제 #5
0
def test_generate_n_primes():
    assert primesieve.generate_n_primes(7) == [2, 3, 5, 7, 11, 13, 17]
def test_generate_n_primes():
    assert primesieve.generate_n_primes(7) == [2,3,5,7,11,13,17]
    assert primesieve.generate_n_primes(5, 100) == [101,103,107,109,113]
예제 #7
0
def test_generate_n_primes():
    assert primesieve.generate_n_primes(7) == [2,3,5,7,11,13,17]
예제 #8
0
def is_prime(num):
    if primesieve.generate_n_primes(1, num)[0] == num:  
        pass
    else : 
        return False
    return True
예제 #9
0
def is_prime(num):
    if primesieve.generate_n_primes(1, num)[0] == num:
        pass
    else:
        return False
    return True