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;
- If the number N in question is even, divide it by 2. Repeat this until N is odd.
- If N ≡ 5 or 7 (mod 8) it cannot be expressed as the sum of a square plus twice another square.
- 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.
A positive number n belongs to this sequence if and only if every prime p == 5, 7 mod 8 dividing n occurs to an even power.
– Henry Apr 09 '22 at 11:57