projecteuler---->problem=27----Quadratic primes
来源:互联网 发布:ps软件的使用方法 编辑:程序博客网 时间:2024/05/19 13:10
Euler discovered the remarkable quadratic formula:
n² + n + 41
It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41.
The incredible formula n² − 79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, −79 and 1601, is −126479.
Considering quadratics of the form:
n² + an + b, where |a| < 1000 and |b| < 1000where |n| is the modulus/absolute value of n
e.g. |11| = 11 and |−4| = 4
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.
import math,timedef isOk(temp):if temp < 0: return Falsefor i in range(2,int(math.sqrt(temp))+1):if temp%i==0 : return Falsereturn Truebegin = time.time()maxValue=0lastValue=1for a in range(-1000,1001):for b in range(-1000, 1001):n = 0resu = 0while True:temp = n*n + a*n + bif(isOk(temp)):resu+=1n+=1else :breakif resu>maxValue:maxValue = resulastValue = a*bprint lastValueend = time.time()print end-begin
0 0
- projecteuler---->problem=27----Quadratic primes
- Project Euler:Problem 27 Quadratic primes
- Problem 27 Quadratic primes (暴力枚举)
- projecteuler---->problem=10----Summation of primes
- projecteuler---->problem=35----Circular primes
- PE 27 Quadratic primes
- 27 Quadratic primes - Project Euler
- Quadratic primes
- No_27:Quadratic primes
- 欧拉工程第27题:Quadratic primes
- http://projecteuler.net/problem=27 [Answer:-59231]
- http://projecteuler.net/problem=1
- http://projecteuler.net/problem=2
- http://projecteuler.net/problem=3
- http://projecteuler.net/problem=4
- projecteuler---->problem=3----Largest prime factor
- projecteuler---->problem=4----Largest palindrome product
- projecteuler---->problem=6----Sum square difference
- Fizz Buzz programming
- 如果你想学好编程!就一定要看这个!对无论有多厉害的你有很多帮助!
- ActivityManager: Warning: Activity not started, its current task has been brought to the front
- 现场清理sqlserver2008数据库日志语句备份
- .net中使用Ajax
- projecteuler---->problem=27----Quadratic primes
- 演讲大厅安排
- hdu1205 吃糖果(鸽笼原理)
- STL基本用法总结
- canvas块状擦除,擦掉上面图片,漏出下面
- hdu 4961 Boring Sum
- mac 显示桌面快捷键
- UVA 282 - Rename(字符串处理)
- CopyOnWriteArrayList