示例#1
0
def primeFactors(n, primos=None):
    factors = list()
    if primos == None:
        primos = getPrimes(n)
    dividendo = n
    while dividendo > 1:
        for i in range(0, len(primos)):
            if dividendo % primos[i] == 0:
                factors.append(primos[i])
                dividendo = dividendo // primos[i]
                break
    return factors
示例#2
0
def divisors(N,primos):
	facts = primeFactors(N,primos)
	divs = 1
	factset = set()
	for f in facts:
		factset.add( (f,facts.count(f)) )
	for (p,e) in factset:
		divs *= e+1
	return divs 

def triangle(N):
	tri = 0
	for i in range(1,N+1):
		tri += i
	return tri

if __name__ == '__main__':	
	found = False
	i = 0
	tri = triangle(i)
	primos = getPrimes(20000000)
	while not found:
		divs = divisors(tri,primos)
		print("O triangulo #{0} - {1} tem {2} divisores".format(i,tri,divs))
		if divs >= 500:
			found = True
			print("Terminado")
		else:
			i += 1
			tri += i
示例#3
0
from p010 import getPrimes
from collections import deque

def maxSequence(p,primes):
	seq = deque()
	_sum = 0
	_max = 0
	i = 0
	while i < len(primes) and primes[i] <= p//2+1:
		_sum += primes[i]
		seq.append(primes[i])
		while _sum > p:
			_sum -= seq.popleft()
		if _sum == p:
			if len(seq) > _max:
				_max = len(seq)
		i += 1
	return _max

if __name__ == '__main__':
	_maxp = -1
	_maxs = -1
	primes = getPrimes(1000000)
	for p in primes:
		print(p)
		s = maxSequence(p,primes)
		if s > _maxs:
			_maxp = p
			_maxs = s
	print(str(_maxp) + ": " + str(_maxs))
示例#4
0
from p010 import getPrimes
from p007 import isPrime

rangeB = getPrimes(1000)
negativos = []
for p in rangeB:
	negativos.append(-p)
rangeB = negativos + rangeB

_maxA = -1
_maxB = -1
_maxPrimos = 0

for a in range(-999,1000):
	if a % 100 == 0:
		print("a = {0}... ".format(a),end="",flush=True)
	for b in rangeB:
		sequencia = True
		n = 0
		while sequencia:
			if isPrime(n**2 + a*n + b):
				n += 1
			else:
				sequencia = False
		if n > _maxPrimos:
			_maxPrimos = n
			_maxA = a
			_maxB = b

print("\na = {a}\nb = {b}\nprimos = {p}\na * b = {ab}".format(a=_maxA,b=_maxB,p = _maxPrimos,ab=_maxA*_maxB))