-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb27.pl
More file actions
44 lines (44 loc) · 837 Bytes
/
Prob27.pl
File metadata and controls
44 lines (44 loc) · 837 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
#! usr/bin/perl
#Matthew Digman
use strict;
use warnings;
sub sieve{
my @nums=(2..1000000);
my @primes;
while(@nums){
my $prime=shift @nums;
if(defined $prime){
push @primes, $prime;
for(my $itr=$prime-1; $itr<@nums;$itr+=$prime){
if(defined $nums[$itr]){
$nums[$itr]=undef;
}
}
}
}
@primes;
}
my @primes=sieve;
my %primes;
my $max_length=0;
my $ans;
$primes{$_}=1 for(@primes);
for(my $itr1=-999; $itr1<1000; $itr1++){
unless(exists $primes{abs $itr1}){
next;
}
for(my $itr2=-999; $itr2<1000; $itr2++){
unless(exists $primes{abs $itr2}){
next;
}
my $count;
for($count=0; exists $primes{$count**2+$itr1*$count+$itr2}; $count++){
1;
}
if($count>$max_length){
$max_length=$count;
$ans=$itr1*$itr2;
}
}
}
print "$max_length $ans\n";