summaryrefslogtreecommitdiffstats
path: root/046.pl
diff options
context:
space:
mode:
Diffstat (limited to '046.pl')
-rwxr-xr-x046.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/046.pl b/046.pl
new file mode 100755
index 0000000..e424abc
--- /dev/null
+++ b/046.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Math::Prime::XS qw/sieve_primes/;
+use integer;
+
+my @primes = sieve_primes(1e6);
+my %primes = map { $_, 1 } @primes;
+
+N: for my $n (2..100000) {
+ my $oddn = $n * 2 - 1;
+ next if exists $primes{$oddn};
+ for my $m (1..sqrt($oddn)) {
+ my $possible_prime = $oddn - 2 * $m**2;
+ next N if $primes{$possible_prime};
+ }
+ print "$oddn\n";
+ last;
+}