Beispiel #1
0
def right_trunc(num):
    while num != 0:
        if check_prime(num):
            num = (num - (num % 10)) / 10
        else:
            return False
    return True
Beispiel #2
0
def left_trunc(num):
    i = 1
    temp = 0
    while (temp != num):
        temp = num % (10**i)
        if check_prime(temp):
            i = i + 1
        else:
            return False
    return True
Beispiel #3
0
def distinct_factors(num):
    if check_prime(num):
        return 1
    number = copy.copy(num)
    i = 3
    count = 0

    if number % 2 == 0:
        while number % 2 == 0:
            number = number / 2
        count = 1

    while (count <= 4 and number != 1):
        if number % i == 0:
            if check_prime(i):
                count = count + 1
                while number % i == 0:
                    number = number / i
        i = i + 2

    return count
Beispiel #4
0
 list_h.remove(
     h)
 if (len(list_h)
         != 0):
     for i in list_h:
         if (check_prime(
                 int(
                     a
                     +
                     b
                     +
                     c
                     +
                     d
                     +
                     e
                     +
                     f
                     +
                     g
                     +
                     h
                     +
                     i
                 )
         )):
             pan_prime.append(
                 int(
                     a
                     +
                     b
Beispiel #5
0
# 15 = 7 + 2×2^2
# 21 = 3 + 2×3^2
# 25 = 7 + 2×3^2
# 27 = 19 + 2×2^2
# 33 = 31 + 2×1^2
#
# It turns out that the conjecture was false.
#
# What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

from math import *
from common_functions import check_prime, timing

timer = timing()

flag = True
odd_comp = 35
while (flag):
    if (not(check_prime(odd_comp))):
        GoldBach = False
        for i in range (3, odd_comp, 2):
            if (check_prime(i)):
                if (sqrt((odd_comp - i) / 2) == int(sqrt((odd_comp - i) / 2))):
                    GoldBach = True
        if (not GoldBach):
            flag = False

    odd_comp = odd_comp + 2

timer("The smallest odd number that does not satisfy Goldbach's conjecture is {}".format(odd_comp - 2))
Beispiel #6
0
# -*- coding: utf-8 -*-

# What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20 ?
from common_functions import check_prime, timing

def highest_power_less_than_number(prime, number):
    a = 1
    while(a <= number):
        a = a * prime
    return a/prime

timer = timing()

i = 2
ans = 1
number = 20
while (i <= number):
    is_prime = check_prime(i)
    if (is_prime):      # All primes greater than 5 have only these numbers in decimal place
        ans = ans * highest_power_less_than_number(i, number)
    i = i + 1

timer("The smallest positive number that is evenly divisible by all of the numbers from 1 to 20 is {}".format(ans))
Beispiel #7
0
# n2+an+b, where |a|<1000 and |b|≤1000
#
# where |n| is the modulus/absolute value of n
# e.g. |11|=11 and |−4|=4
# Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.

from math import *
from common_functions import timing, check_prime, PrimeSieve

timer = timing()
b = PrimeSieve(1000)

a_b = []
for i in range(-999, 1000, 1):
    for j in b:
        if (((i + j + 1) > 0) and (check_prime(i + j + 1))):
            a_b.append([i, j])

n = 0
while (len(a_b) != 1):
    for ab in a_b[:]:
        if len(a_b) != 1:
            if (((n**2) + (ab[0] * n) + ab[1]) <= 0):
                a_b.remove(ab)
                continue
            val = check_prime(((n**2) + (ab[0] * n) + ab[1]))
            if (val != 1):
                a_b.remove(ab)
    n = n + 1

timer("The product of the coefficients is {}".format(a_b[0][0] * a_b[0][1]))
Beispiel #8
0
        if ((num % 2) == 0):
            return False
        else:
            num = (num - (num % 10)) / 10
    return True

def rotate_num(num):
    last_digit = num % 10
    num = (num - (last_digit)) / 10
    return (int(float(str(last_digit) + str(num))))

timer = timing()

count = 13
for i in range(101, 1000000, 2):
    if check_any_even_number(i):
        if (check_prime(i)):
            flag = 1
            l = len(str(i))
            for j in range (0, l):
                i = rotate_num(i)
                if (check_prime(i)):
                    continue
                else:
                    flag = 0
                    break
            if flag == 1:
                count = count + 1

timer("There are {} circular primes below one million".format(count))