def main(): prime = Prime() prime_list = [] prime_under_one_million = [] for p in prime.get_prime(): if p < 1000: prime_list.append(p) prime_under_one_million.append(p) elif p < 1000000: prime_under_one_million.append(p) else: break negative_prime_list = [0 - v for v in sorted(prime_list, reverse=True)] negative_prime_list.extend(prime_list) # b is try to be big, then n&b co efficient will be big # a is try to be small, then current_max_combination = 0 for a in negative_prime_list: for b in negative_prime_list: combi_cnt = 0 for n in count(): if n * n + a * n + b not in prime_under_one_million: break else: combi_cnt += 1 if combi_cnt > current_max_combination: print 'find an greater combination: a={}, b={} has {} combinations'.format( a, b, combi_cnt) current_max_combination = max(current_max_combination, combi_cnt)
def main(min_prime, max_prime): """Parse the args and if all is good, summon Prime to do the computation.""" logger.debug('Inside main()') print('Calculating prime numbers between {} and {}'.format( min_prime, max_prime)) primes = Prime().primes_between(start=min_prime, stop=max_prime) print('Found {} prime numbers'.format(len(primes))) print(primes)
def nextprime(np): if (np <= 1): return 2 prime = np found = False if (Prime(prime) == True): return np while (not found): prime += 1 if (Prime(prime) == True): found = True return prime
def main(): prime_ins = Prime() prime_hash = dict() circular_prime_list = list() for i in prime_ins.get_prime(): if i < TARGET: prime_hash[i] = True else: break for prime in prime_hash: circular_list = [] for i in range(1, len(str(prime))): circular_list.append(int(''.join(str(prime)[i:] + str(prime)[0:i]))) for num in circular_list: if not num in prime_hash: break else: print "circular prime found: {}".format(prime) circular_prime_list.append(prime) print "count of all circular prime is {}".format(len(circular_prime_list))
import sys import copy import math from collections import deque from prime import Prime prime_man = Prime() #obtain the name of the input def fileName(): filename = 'input' if len(sys.argv) > 1: filename = sys.argv[1] else: print("File was not indicated") exit() return filename fn = fileName() file = open(fn, 'r') out = open('output', 'w') line_number = 1; testcase = 1 max_testcases = 0 tc_ln = 0 while True: line = file.readline() if line: line = line.replace("\n","") inputs = line.split(" ")
def test_prime(self): """.""" self.assertEqual(bool(Prime(7)), True) self.assertEqual(bool(Prime(6)), False)
#!/usr/bin/env python # -*- coding: utf-8 -*- from dh import DH from prime import Prime import random if __name__ == '__main__': message = "Mensagem secreta?!" c_private = random.randrange(1, 2048) j_private = random.randrange(1, 2048) prime = Prime() prime.createPrimeNumbers() print('[+] Private Key Carlos: ' + str(c_private)) print('[+] Private Key Jose: ' + str(j_private)) print('[+] Public key 1: ' + str(prime.publicKey1)) print('[+] Public key 2: ' + str(prime.publicKey2)) Carlos = DH(c_private, prime.publicKey1, prime.publicKey2) Jose = DH(j_private, prime.publicKey1, prime.publicKey2) partial_key_carlos = Carlos.generatePartialKey() partial_key_jose = Jose.generatePartialKey() print('[+] partial key Carlos: ' + str(partial_key_carlos)) print('[+] partial key Jose: ' + str(partial_key_jose))
def setUp(self): self.prime = Prime()
from prime import Prime """ The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. """ prime_list = Prime() prime_sum = 0 for i in prime_list.get_prime(): if i < 2000000: prime_sum += i else: print prime_sum break
def setup_method(self): self.prime = Prime()
""" Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024 52=25, 53=125, 54=625, 55=3125 If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100? """ prime_list = list() prime_ins = Prime() for prime in prime_ins.get_prime(): if prime > 100: break else: prime_list.append(prime) def is_prime(n=None): for i in range(2, n): if n % i == 0: return False else: return True
from armstrong import Armstrong from factor import Factor from factorial import Factorial from fibonacci import Fibonacci from palindrome import Palindrome from prime import Prime print("Armstrong", bool(Armstrong(153))) print("Fibonacci", [i for i in Fibonacci(5)]) print("Palindrome", bool(Palindrome(12321))) print("Prime", bool(Prime(10007))) print("Factors", [i for i in Factor(23)]) print("Factorial", Factorial(6)())