问题描述:
Euler published 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.
Using computers, 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:
解决问题:
利用题目本身的限制条件,因为a和b是1000以下,那么先使用boolean[] prime = new boolean[1000001];
public static boolean IsPrime(int number){
boolean result = true;
if(number%2==0){
result = false;
}else{
int middle = (int)Math.sqrt(number);
for(int i=3; i<=middle; i+=2){
if(number%i==0){
result = false;
break;
}
}
}
return result;
}
public static void find(){
int a =0, b=0;
int max_len = 0;
//先找出1000以内的所有素数
boolean[] prime = new boolean[1000001];
Arrays.fill(prime, false);
for(int i=2;i<=1000001;i++){
if(IsPrime(i)){
prime[i] = true;
}
}
for(int i=-1000; i<=1000; i++){ //循环a
for(int j=-1000; j<=1000; j++){ //循环b
int n;
for( n=0; n<Math.abs(j); n++){
int value = n*n+ i*n + j;
if(value>0&&prime[value]){
;
}else{
break;
}
}
if(max_len<n){
a = i;
b = j;
max_len = n;
}
}
}
System.out.println("a:"+a+",b:"+b+",len"+max_len);
System.out.println(a*b);
}
分享到:
相关推荐
27. Creation of a botnet requires an attacker to find vulnerability in some application or system (e.g. exploiting the buffer overflow vulnerability that might exist in an application). After finding ...
The Shellcoder's Handbook 2nd Edition About the Authors vii Acknowledgments xi ...The Address Problem 27 The NOP Method 33 Defeating a Non-Executable Stack 35 Return to libc 35 Conclusion 39
### 数值分析第四版答案解析 #### 一、概述 《数值分析》是一门重要的计算机科学与数学交叉学科,主要研究如何使用计算机有效地解决数学问题。本书为《数值分析》第四版的答案集,包含了该教科书的主要内容概要及...
4.1. G1 还是G2 it's a problem 27 4.2. G1和G2的硬件对比: 27 4.3. 编者注: 29 5. 移动应用程序 29 5.1. 大度咨询发布手机软件发展报告 30 5.2. Apple AppStore 用户喜好精细化分析 58 5.3. android应用分类: 67...
26. 问题,苦恼 - problem 27. 〔用手或器具〕击;打 - hit 28. 立即;马上 - immediately 29. 陷入;参与 - get involved 30. 她自己 - herself 31. 绷带 - bandage (n/v) 32. 生病的;有病的 - ill 33. 膝;膝盖 -...
--- Problem Solving & Traditional AI Problems......Page 27 POLyA’s five sTePs fOr PrOBLem sOLvinG......Page 28 PrOBLem-sOLvinG Techniques......Page 33 humAn WinDOW......Page 44 humAn WinDOW criTeriA ...
编译和运行C++程序是学习C++语言的基础,本教材在第27页提供了编译和运行的详细步骤,为初学者打下良好的实践基础。算术运算符及其优先级是编写有效算法的核心,第71页对此进行了介绍,而第81页则讨论了在使用赋值...
在这个名为“0-1-knapsack-problem-master (27).zip”的压缩包中,我们可以推测包含的是关于0-1背包问题的C语言实现代码。C语言是一种底层、高效的编程语言,常用于解决这种算法问题。 0-1背包问题的基本定义如下:...
在这个名为"0-1-knapsack-problem-master (27)c.zip"的压缩包中,我们预计会找到一个C语言实现的0-1背包问题解决方案。C语言是一种底层、高效且灵活的编程语言,非常适合解决这类计算密集型的问题。 在C语言中解决0...
通过逻辑推理和组合数学的方法,我们可以发现这四个砝码的重量分别为1磅、3磅、9磅和27磅。这是因为,使用这四个砝码可以称量从1到40磅的所有整数重量。例如,要称量1磅的物品,只需使用1磅的砝码;如果要称量2磅,...
例如,给定质数2, 3, 和 5,Hamming序列H(2, 3, 5)是2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, ...。题目要求我们找到H(p1, p2, p3)序列中的第i个元素,其中i是一个给定的正整数。 输入数据包括三...
xml解析器失败时候可以尝试打开开始-运行-cmd 输入命令来进行解决
在"0-1-knapsack-problem-master (27)c.zip"这个压缩包中,很可能包含了C语言实现0-1背包问题的源代码示例。通过阅读和理解这些代码,你可以深入理解动态规划方法以及如何将其应用于解决实际问题。同时,这也可以...
离线安装包,亲测可用
sfOnlyThisForm.News in 3.70 10/27/2005*Support TAdvPageControl.*Support TRzMenuButton, TcxButton with cxbkDropDownButton.*work with RECREATEWND message for skined control has scrollbar.*Fix a memory ...
离线安装包,亲测可用
Delphi VCLSkin 5.30 ... VCLSkin is a component to create skinnable user interface for Delphi/C++Builder application, It is easy to use, just put one component on mainform, ...* fix caption paint problem...
MD5_STEP(HH, c, d, a, b, block[15], 0x1fa27cf8, 16); MD5_STEP(HH, b, c, d, a, block[2], 0xc4ac5665, 23); MD5_STEP(II, a, b, c, d, block[0], 0xf4292244, 6); MD5_STEP(II, d, a, b, c, block[7], 0x432...
5.20.27 xe4 ! Defined names with non-ansi chars could cause problems. ! Wrong UTF-8 encoding on some pivot tables. ! When inserting rows, not all formulas where adjusted. ! Problem with hyperlinks to ...
- [题目27](http://acm.pku.edu.cn/JudgeOnline/problem?id=1190) —— 深度优先搜索剪枝。 - [题目28](http://acm.pku.edu.cn/JudgeOnline/problem?id=1084) - [题目29]...