aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-08-15 10:02:48 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-08-15 10:02:48 +0800
commitac1325e6eee9ccff046085735d61aa969dc09b75 (patch)
tree751699f14eca8f876af2288c7ece353431235cbe
parent396867334ee4fe6295c5fa8415537f857e9b0063 (diff)
downloadperlweeklychallenge-club-ac1325e6eee9ccff046085735d61aa969dc09b75.tar.gz
perlweeklychallenge-club-ac1325e6eee9ccff046085735d61aa969dc09b75.tar.bz2
perlweeklychallenge-club-ac1325e6eee9ccff046085735d61aa969dc09b75.zip
improve bound on ch-1.pl
-rw-r--r--challenge-125/cheok-yin-fung/perl/ch-1.pl5
1 files changed, 5 insertions, 0 deletions
diff --git a/challenge-125/cheok-yin-fung/perl/ch-1.pl b/challenge-125/cheok-yin-fung/perl/ch-1.pl
index 6258feda8a..7a700d2ed0 100644
--- a/challenge-125/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-125/cheok-yin-fung/perl/ch-1.pl
@@ -37,6 +37,11 @@ sub pyth ($n) {
}
}
+
+ # (C+1)^2 - C^2 = 2C + 1
+ # 2C + 1 <= n^2
+ # C <= (n^2-1)/2
+
for my $b0 ($n+1..int ($n*$n-1)/2) {
my $is_sq = $b0*$b0 + $n*$n;
if (sqrt($is_sq) == int sqrt($is_sq)) {