diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-08-15 10:02:48 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-08-15 10:02:48 +0800 |
| commit | ac1325e6eee9ccff046085735d61aa969dc09b75 (patch) | |
| tree | 751699f14eca8f876af2288c7ece353431235cbe | |
| parent | 396867334ee4fe6295c5fa8415537f857e9b0063 (diff) | |
| download | perlweeklychallenge-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.pl | 5 |
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)) { |
