Math::NumSeq::HypotCount -- how many times as sum of two squares
use Math::NumSeq::HypotCount; my $seq = Math::NumSeq::HypotCount->new; my ($i, $value) = $seq->next;
In progress ...
The counts of how many times i occurs as the sum of two squares i=A^2+B^2 for integer A,B.
1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, ...
One or both A,B can be zero, but swapping to B^2+A^2 is not reckoned as a different way. For example i=5 has just one way 1^2+2^2=5. But i=6 has no way to add two squares to make 6.
Allowing A=0 means the perfect squares i=k^2 all have a count of at least one way 0^2+k^2 = k^2, and there may be more ways too.
See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.
$seq = Math::NumSeq::HypotCount->new ()
Create and return a new sequence object.
$value = $seq->ith($i)
Return the number of ways $i can be expressed as the sum of two squares.
$i
This requires factorizing $i and the current code has a hard limit of 2**32 on $i, in the interests of not going into a near-infinite loop.
$bool = $seq->pred($value)
Return true if $value occurs as a count. All counts 0 up occur so this is simply integer $value >= 0.
$value
$value >= 0
Math::NumSeq, Math::NumSeq::PythagoreanHypots
http://user42.tuxfamily.org/math-numseq/index.html
Copyright 2011, 2012 Kevin Ryde
Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
To install Math::NumSeq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Math::NumSeq
CPAN shell
perl -MCPAN -e shell install Math::NumSeq
For more information on module installation, please visit the detailed CPAN module installation guide.