-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler.27.java
More file actions
61 lines (53 loc) · 809 Bytes
/
Euler.27.java
File metadata and controls
61 lines (53 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class Euler27
{
public static boolean isPrime( long number )
{
if( number < 2 )
{
return false;
}
else if ( number == 2 )
{
return true;
}
else
{
for( long i=2; i<=Math.sqrt(number); i++ )
{
if( number%i == 0 )
{
return false;
}
}
}
return true;
}
public static void main(String[] args)
{
int result = 0;
int max = 0;
for( int a=-999; a<=999; a++ )
{
for( int b=-999; b<=999; b++ )
{
int n = 0;
int number = 0;
while(true)
{
number = n*n + a*n + b;
if( !isPrime(number) )
{
break;
}
n++;
}
if( n > max )
{
max = n;
result = a * b;
}
}
}
System.out.println( result );
}
}