Esempio n. 1
0
def main():
    valuesOfB = []
    for x in range( 2, 1000 ):
        if isPrime( x ):
            valuesOfB.append( x )
            valuesOfB.append( -x )

    mostPrimes = 0
    bestA = 0
    bestB = 0
    for a in range( -999, 1000, 2 ):
        for b in valuesOfB:
            n = 0
            while not (n**2 + a*n + b) == 0 and \
                isPrime( n**2 + a*n + b ):
                n += 1
            if n > mostPrimes:
                mostPrimes = n
                bestA = a
                bestB = b
    print( "Quadratic equation n^2 + an + b with |a| < 1000, |b| < 1000 that\n \
    produces the most primes for consecutive values of n, starting at n = 0: ")
    print( "n^2 + (" + str( bestA ) + ")n + (" + str( bestB ) + ") produces " + \
        str( mostPrimes ) + " consecutive primes starting from n = 0. " )
    print( "Product of " + str( bestA ) + " and " + str( bestB ) + " is " + \
        str( bestA * bestB ) )
Esempio n. 2
0
 def updateNumOfPrimesOnDiagonals( self, sl ):
     if self.primesInDiag == 0:
         for num in diagonalsOfSpiral( sl ):
             if isPrime( num ):
                 self.primesInDiag += 1
     else:
         for num in getAdditionalDiagsOfSpiral( sl ):
             if isPrime( num ):
                 self.primesInDiag += 1