-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem10.pl
More file actions
executable file
·56 lines (50 loc) · 1 KB
/
problem10.pl
File metadata and controls
executable file
·56 lines (50 loc) · 1 KB
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
#!/bin/perl -Tw
my @primes;
push @primes, 2;
push @primes, 3;
push @primes, 5;
push @primes, 7;
for (my $number=12; ; $number += 6) {
print ".";
$check1 = $number - 1;
$check2 = $number + 1;
$divisible = 0;
for my $prime (@primes) {
if ($prime * $prime > $check1) {
last;
}
if ($check1 % $prime == 0) {
$divisible = 1;
last;
}
}
if ($divisible == 0) {
push @primes, $check1;
}
$divisible = 0;
for my $prime (@primes) {
if ($prime * $prime > $check2) {
last;
}
if ($check2 % $prime == 0) {
$divisible = 1;
last;
}
}
if ($divisible == 0) {
push @primes, $check2;
}
if ($number % 600 == 0) {
print "$number\n";
}
if ($primes[-1] >= 2000000) {
last;
}
}
pop @primes;
my $total = 0;
for my $prime (@primes) {
print "Adding $prime...\n";
$total += $prime;
}
print "Total: $total\n";