Re: Integer test for perfect square
- From: bert <bert.hutchings@xxxxxxxxxxxxxx>
- Date: Thu, 12 Mar 2009 10:24:02 -0700 (PDT)
On 12 Mar, 16:58, jimwa...@xxxxxxxxx wrote:
On Mar 12, 10:46 am, Jack Schmidt <Jack.Schmidt.SciM...@xxxxxxxxx>
wrote:
Is there an integer test for a perfect square? Say I
have a large positive integer (1000 digits), and I
want to know if it's a perfect square, and I don't
have floating point available. I ended up getting
around this by factoring the number, but I wonder if
there's a quicker way.
See Henri Cohen's "A course in computational algebraic
number theory." Springer-Verlag, 1993. ISBN 3-540-55640-0
http://www.ams.org/mathscinet-getitem?mr=1228206
You want algorithm 1.7.3. Roughly speaking, you
first check if the number is a square modulo some
small numbers (11, 63, 64, 65 is suggested), then
square the integer square root.
This is much faster than factoring.
I guess Cohen outlines a way to find the integer square root without
using floating point? Some form of Newton's method?
Unlikely. There is an algorithm, resembling long division,
which rapidly finds the integer floor R of the square root
of any integer N, and the remainder S, i.e. N = R^2 + S
where 0 <= S <= 2R. You can find a description of it at:
www.mathpath.org/Algor/squareroot/algor.square.root.why.htm
and on various other web sites.
The algorithm was taught in schools up until perhaps 1960,
so only quite elderly people are familiar enough with it
to just do it on automatically on paper. But it could be
expected to be the method of choice in a multiple-precision
integer package. I have implemented it several times, in
different languages. Newton's method would be much slower.
--
.
- Follow-Ups:
- Re: Integer test for perfect square
- From: Herman Rubin
- Re: Integer test for perfect square
- From: riderofgiraffes
- Re: Integer test for perfect square
- References:
- Integer test for perfect square
- From: jimward2
- Re: Integer test for perfect square
- From: Jack Schmidt
- Re: Integer test for perfect square
- From: jimward2
- Integer test for perfect square
- Prev by Date: Re: Integer test for perfect square
- Next by Date: Re: Other result on asymptotics
- Previous by thread: Re: Integer test for perfect square
- Next by thread: Re: Integer test for perfect square
- Index(es):
Relevant Pages
|