-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheuler27.pl
More file actions
executable file
·50 lines (46 loc) · 888 Bytes
/
euler27.pl
File metadata and controls
executable file
·50 lines (46 loc) · 888 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
#!/usr/bin/perl -w
use strict;
my %primes = (
'2' => 1,
'3' => 1,
'5' => 1,
);
my @primes = (2, 3, 5);
sub isprime {
my $num = shift;
return 1 if (exists $primes{$num});
foreach (@primes) {
return 0 if ($num % $_ == 0);
}
push @primes, $num;
$primes{$num} = 1;
return 1;
}
foreach (7..10000) {
isprime($_);
}
my $a;
my $b;
my $n;
my $big = 0;
my $result;
my $tmp;
foreach $a (-999..999) {
next unless( $a % 2);
foreach $b (101..999) {
$n = 1;
while (1) {
$tmp = $n**2 + $a*$n + $b;
last unless (exists $primes[$b]);
unless (isprime($tmp)) {
if ($n > $big) {
$big = $n;
$result = $a*$b;
}
last;
}
$n+=2;
}
}
}
print "$result\n";