Ejemplo n.º 1
0
def problem49():
    choice = xrange(1489, 3340, 2)
    for n in choice:
	if not prime.hasFactors(n, primes):
	    m1, strn = n+3330, str(n)
	    strm1, setn = str(m1), set(strn)
	    if set(strm1)==setn and not prime.hasFactors(m1, primes):
		m2 = m1+3330
		if set(str(m2))==setn and not prime.hasFactors(m2, primes):
		    return strn+strm1+str(m2)    
Ejemplo n.º 2
0
def problem27():
    """http://projecteuler.net/index.php?section=problems&id=27
    >>> problem27()
    -59231
    """
    max_pair = (0,0,0)
    primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
    for a in xrange(-999, 1000):
        for b in xrange(max(2, 1-a), 1000): # b >= 2, a + b + 1 >= 2
            n, count = 0, 0
            while True:
                v = n*n + a*n + b
                v = v <=0 and -v or v
                if v > primes[-1]:
                    prime.primesBelow_fast(v, primes)
                    if prime.isprime_fast(v, primes): count = count + 1
                    else: break
                else:
                    if not prime.hasFactors(v, primes): count = count + 1
                    else: break
                n = n + 1
            if count > max_pair[2]:
                max_pair = (a,b,count)
    return max_pair[0] * max_pair[1]