0

I have discovered an algorithm to determine whether or not a number can be expressed as the sum of a square plus twice another square. I find it hard to believe that this algorithm is not already known; Fermat did some investigation in 1654! But I cannot find this rule on the internet, much less an explanation of why it works. My question is; is this rule already known, and how can one prove rigorously that it works? The algorithm is as follows;

  1. If the number N in question is even, divide it by 2. Repeat this until N is odd.
  2. If N ≡ 5 or 7 (mod 8) it cannot be expressed as the sum of a square plus twice another square.
  3. If N ≡ 1 or 3 (mod 8) factorise N if there is at least one odd prime factors of form 8i+1 or 8i+3 and any odd prime factors of form 8i+5 or 8i+7 have even exponents, N can be expressed as the sum of a square plus twice another square, otherwise it cannot. Steps 1 and 2 are not actually necessary, but may avoid fully factorising N.

0 Answers0