diff options
| author | Michael Lee Firkins <michael@firkins> | 2022-03-31 20:32:08 +0700 |
|---|---|---|
| committer | Michael Lee Firkins <michael@firkins> | 2022-03-31 20:34:01 +0700 |
| commit | c10945b03e175dafc4d22f319ebe4d09de9de480 (patch) | |
| tree | 1b4cd87f6b6291c39b12ebbf4e16c58aa2f29390 | |
| parent | ce2c5558f6ee712548b43fc6f307eabff964bc93 (diff) | |
| download | perlweeklychallenge-club-c10945b03e175dafc4d22f319ebe4d09de9de480.tar.gz perlweeklychallenge-club-c10945b03e175dafc4d22f319ebe4d09de9de480.tar.bz2 perlweeklychallenge-club-c10945b03e175dafc4d22f319ebe4d09de9de480.zip | |
simplify formula for cuban prime
| -rw-r--r-- | challenge-158/pokgopun/go/ch-2.go | 7 | ||||
| -rw-r--r-- | challenge-158/pokgopun/perl/ch-2.pl | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/challenge-158/pokgopun/go/ch-2.go b/challenge-158/pokgopun/go/ch-2.go index f3073b8ef8..161f916816 100644 --- a/challenge-158/pokgopun/go/ch-2.go +++ b/challenge-158/pokgopun/go/ch-2.go @@ -2,16 +2,17 @@ package main import ( "fmt" - "math" ) const max = 1000 func main() { - i := 2 + //i := 2 + i := 1 var cp string for { - n := int(math.Pow(float64(i), 3) - math.Pow(float64(i-1), 3)) + //n := int(math.Pow(float64(i), 3) - math.Pow(float64(i-1), 3)) + n := 3*i*i + 3*i + 1 if n > max { break } diff --git a/challenge-158/pokgopun/perl/ch-2.pl b/challenge-158/pokgopun/perl/ch-2.pl index 9db7a1a759..04dfcf9892 100644 --- a/challenge-158/pokgopun/perl/ch-2.pl +++ b/challenge-158/pokgopun/perl/ch-2.pl @@ -5,9 +5,11 @@ use Math::Prime::Util qw/is_prime/; my $n = shift; $n = 1000 unless $n && $n =~ /^\d+$/; my $o = ""; -my $i = 2; +#my $i = 2; +my $i = 1; { - my $cp = $i**3 - ($i-1)**3; + #my $cp = $i**3 - ($i-1)**3; + my $cp = 3*$i*$i + 3*$i + 1; last if $cp > $n; $o .= ", $cp" if is_prime($cp); $i++; |
