How many integers between 1 and 100 inclusive can be expressed as either the sum or difference of two perfect squares?
Note: 0 is always considered as a perfect square.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Great solution, Mark. Thanks for posting it. For the numbers that can be written as a sum I was going to use the 4 m + 3 rule as well.
Here is the OEIS entry for the positive integers that can't be written as the sum or difference of perfect squares.
A prime integer p ∈ N is prime in: Z [ i ] if and only if: p ≡ 3 ( m o d 4 ) ; Why ???
Log in to reply
If p is a prime in Z which is not prime in the Gaussian integers, it must be equal to z z = ∣ z ∣ 2 for some Gaussian integer z , and so must be the sum of two square integers. The sum of two integer squares cannot be congruent to 3 modulo 4 , so primes p that are congruent to 3 modulo 4 are prime in the Gaussian integers.
The fact that primes congruent to 1 modulo 4 are reducible in the Gaussian integers follows from the fact that − 1 is a quadratic residue modulo such primes.
Log in to reply
Log in to reply
@Kushal Bose – If p = 4 n + 1 is prime, use Wilson's Theorem to show that ( ( 2 n ) ! ) 2 ≡ − 1 ( m o d p ) . Thus − 1 is a quadratic residue modulo p , and we can find an integer a such that p divides a 2 + 1 = ( a + i ) ( a − i ) . Since p divides neither a + i nor a − i , we deduce that p cannot be prime in Z [ i ] .
Problem Loading...
Note Loading...
Set Loading...
Since ( n + 1 ) 2 − n 2 = 2 n + 1 ( n + 1 ) 2 − ( n − 1 ) 2 = 4 n n ≥ 0 we see that odd numbers and multiples of 4 can all be written as a difference of two squares. Moreover, since a 2 − b 2 = ( a + b ) ( a − b ) and a + b , a − b have the same parity, we deduce that all differences of two squares are either odd or multiples of 4 . Thus the only numbers that cannot be written as a difference of two squares are the numbers that are congruent to 2 modulo 4 .
Since a 2 + b 2 = ( a + i b ) ( a − i b ) , the numbers that can be written as a sum of squares are going to be identified by considering factorisation in the Gaussian integers Z [ i ] . A prime integer p ∈ N is prime in Z [ i ] if and only if p ≡ 3 ( m o d 4 ) ; the prime 2 and primes p ≡ 1 ( m o d 4 ) can all be written as a sum of squares of two integers. Thus an integer n can be written as a sum of two squares precisely when its prime factorisation in Z does not contain an odd prime, congruent to 3 modulo 4 , which is repeated an odd number of times.
If n ≡ 6 ( m o d 8 ) , then the prime factorisation of n over Z must contain an odd number of primes congruent to 3 modulo 4 , and this means that such numbers cannot be written as a sum of two squares. There are 1 2 such numbers between 1 and 1 0 0 : 6 , 1 4 , 2 2 , 3 0 , 3 8 , 4 6 , 5 4 , 6 2 , 7 0 , 7 8 , 8 6 , 9 4 .
If n ≡ 2 ( m o d 8 ) , then all but two of these numbers have prime factorisations which mean that they can be written as a sum of two squares. The two exceptions are 4 2 = 2 × 3 × 7 and 6 6 = 2 × 3 × 1 1 .
Thus there are 1 2 + 2 = 1 4 numbers which cannot be written as either a difference or a sum of two squares, and hence there are 8 6 numbers that can.