1

For example, if we have a number like 29873412895, is there an algorithm that can find it as a difference of two squares? Or must you need the factors of the numbers? And what might be the algorithm? Thanks!

Apologies for my previous post, in which I acted very callous.

  • 1
    https://en.wikipedia.org/wiki/Quadratic_sieve – Jack D'Aurizio Jun 22 '15 at 20:46
  • It is sure that once it is written as a difference of two squares, you will have factors (though not necessarily irreducible (prime) factors). So searching for the difference of two squares representation for a number is a factoring strategy that goes back to Fermat (at least). – hardmath Jun 23 '15 at 05:37

2 Answers2

3

If $k=2n+1$ is an odd number, then $k=(n+1)^2-n^2$. Finding other ways is esentially the same as factoring the number.

ajotatxe
  • 66,849
  • 3
    For completeness, numbers of the form $4n+2$ are not expressible as a difference of squares, and numbers of the form $4^m(2n+1)$ are $(2^m(n+1))^2-(2^mn)^2$. – user26486 Jun 22 '15 at 20:54
  • @user26486: Not quite complete $-$ you are forgetting numbers of the form $2^{2m+3}(2n+1)$. – TonyK Jun 23 '15 at 09:04
1

You don't need to factorise anything. Every positive integer can be expressed as one of the following:

  • $2n+1$
  • $4n+2$
  • $4n$

The first and third are differences of two squares:

  • $2n+1=(n+1)^2-n^2$
  • $4n = (n+1)^2-(n-1)^2$

Numbers of the second form can't be expressed as the difference of two squares (because every square is equal to $0$ or $1$ mod $4$, so we can't subtract one from another to get $2$ mod $4$).

TonyK
  • 68,059