How many positive integers from 1 to 1000 can be expressed as the difference of two perfect square?

(0 counts as a perfect square)

Guest Apr 26, 2020

#2**+1 **

n=1;c=0;cycle:b=( (n)^2 - (n-1)^2);d=(n+1)^2 - (n-1)^2;c=sort(c,b,d);n++;if(n<=2000, goto cycle, 0);printc,"Total =", count c

**OUTPUT =751 - which includes zero and 1000. It trurns out that every number can be written as a difference of two perfect squares with the exception of ALL numbers of the form: 4n + 2, which is every 4th number beginning with 2, 6, 10, 14......etc. Or 1/4 of all numbers. The other 3/4 can all be written as the difference of two perfect squares. The above short code verifies this.**

Guest Apr 26, 2020