#16308: Improve sums of squares
-------------------------------------+-------------------------------------
Reporter: jdemeyer | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.3
Component: number theory | Resolution:
Keywords: | Merged in:
Authors: Jeroen Demeyer | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/jdemeyer/ticket/16308 | 6b94a6576031e6e341143a4fc1fd83263a800ed9
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by leif):
Replying to [comment:25 vdelecroix]:
> {{{
> def two_squares_pyx(int n):
> cdef int i,ii,j,nn
> if n < 2:
> return True
>
> i = ii = 0
> while ii < n:
> j = 0
> while j <= i:
> nn = ii + j*j
> if nn >= n:
> break
> j += 1
>
> if nn == n:
> return (i,j)
>
> i += 1
> ii = i*i
>
> raise ValueError("%d is not the sum of 2 squares"%n)
> }}}
Minor correction: `while ii <= n` (such that we get "trivial" solutions
with `j==0` as well). Also, I'd swap i and j, or `return (j,i)`.
--
Ticket URL: <http://trac.sagemath.org/ticket/16308#comment:28>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.