Ejemplo n.º 1
0
def determine_prime(n):
    if n in primes:
        return True
    if n in non_primes:
        return False
    if is_prime(n):
        primes.add(n)
        return True
    else:
        non_primes.add(n)
        return False
Ejemplo n.º 2
0
def determine_prime(n):
    if n in primes:
        return True
    if n in non_primes:
        return False
    if is_prime(n):
        primes.add(n)
        return True
    else:
        non_primes.add(n)
        return False
Ejemplo n.º 3
0
def sqr_diag_generator():
    cant_tot = 1
    cant_primes = 0
    num = 1
    to_sum = 2
    while True:
        for i in range(0,4):
            num += to_sum
            if is_prime(num):
                cant_primes += 1
        to_sum += 2
        cant_tot += 4
        
        yield cant_primes * 100 / cant_tot 
Ejemplo n.º 4
0
def sqr_diag_generator():
    cant_tot = 1
    cant_primes = 0
    num = 1
    to_sum = 2
    while True:
        for i in range(0, 4):
            num += to_sum
            if is_prime(num):
                cant_primes += 1
        to_sum += 2
        cant_tot += 4

        yield cant_primes * 100 / cant_tot
Ejemplo n.º 5
0
#   Finds the largest n-pandigital prime.
#   Copyright (C) 2010  Santiago Alessandri
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#    
#   You can contact me at [email protected]
#   Visit my wiki at http://san-ss.wikidot.com
########################################################################

from CommonFunctions import is_prime
from itertools import permutations

if __name__ == '__main__':
    result = 0
    for i in range(3,10):
        for x in permutations([str(x) for x in range(1,i+1)]):
            x = int(''.join(x))
            if is_prime(x):
                result = max(result, x)
    print("The result is:", result)
Ejemplo n.º 6
0
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#    
#   You can contact me at [email protected]
#   Visit my wiki at http://san-ss.wikidot.com
########################################################################

from CommonFunctions import is_prime

if __name__ == '__main__':
    i = 3
    number = 600851475143
    while number > 1:
        if is_prime(i):
            while (number % i) == 0:
                number //= i
        i += 2
    i -= 2
    print("The result is:", i)

Ejemplo n.º 7
0
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#   You can contact me at [email protected]
#   Visit my wiki at http://san-ss.wikidot.com
########################################################################

from CommonFunctions import find_primes_less_than, is_prime

if __name__ == '__main__':
    max = 0
    primes = find_primes_less_than(1000)
    for b in primes:
        for a in range(-999, 1000):
            n = 0
            tmp = n**2 + a * n + b
            while tmp > 0 and is_prime(tmp):
                n += 1
                tmp = n**2 + a * n + b
            if n > max:
                max = n
                res = (a, b)
    print("The result is:", res[0] * res[1])
Ejemplo n.º 8
0
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#    
#   You can contact me at [email protected]
#   Visit my wiki at http://san-ss.wikidot.com
########################################################################

from CommonFunctions import is_prime

if __name__ == '__main__':
    cant = 2
    result = 3
    
    while cant < 10001:
        result += 2
        while not is_prime(result):
            result += 2
        cant += 1
    print("The result is:", result)
Ejemplo n.º 9
0
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#   You can contact me at [email protected]
#   Visit my wiki at http://san-ss.wikidot.com
########################################################################

from CommonFunctions import find_primes_less_than, is_prime

if __name__ == "__main__":
    max = 0
    primes = find_primes_less_than(1000)
    for b in primes:
        for a in range(-999, 1000):
            n = 0
            tmp = n ** 2 + a * n + b
            while tmp > 0 and is_prime(tmp):
                n += 1
                tmp = n ** 2 + a * n + b
            if n > max:
                max = n
                res = (a, b)
    print("The result is:", res[0] * res[1])