Sum or difference... or both

How many integers between 1 and 100 inclusive can be expressed as either the sum or difference of two perfect squares?

Note: 0 0 is always considered as a perfect square.


Inspiration .


The answer is 86.

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.

1 solution

Mark Hennings
Apr 25, 2017

Since ( n + 1 ) 2 n 2 = 2 n + 1 ( n + 1 ) 2 ( n 1 ) 2 = 4 n n 0 (n+1)^2 - n^2 \; = \; 2n+1 \hspace{1cm} (n+1)^2 - (n-1)^2 \; = \; 4n \hspace{2cm} n \ge 0 we see that odd numbers and multiples of 4 4 can all be written as a difference of two squares. Moreover, since a 2 b 2 = ( a + b ) ( a b ) a^2 - b^2 = (a+b)(a-b) and a + b , a b a+b,a-b have the same parity, we deduce that all differences of two squares are either odd or multiples of 4 4 . Thus the only numbers that cannot be written as a difference of two squares are the numbers that are congruent to 2 2 modulo 4 4 .

Since a 2 + b 2 = ( a + i b ) ( a i b ) a^2 + b^2 = (a+ib)(a-ib) , 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 ] \mathbb{Z}[i] . A prime integer p N p \in \mathbb{N} is prime in Z [ i ] \mathbb{Z}[i] if and only if p 3 ( m o d 4 ) p \equiv 3 \pmod{4} ; the prime 2 2 and primes p 1 ( m o d 4 ) p \equiv 1 \pmod{4} can all be written as a sum of squares of two integers. Thus an integer n n can be written as a sum of two squares precisely when its prime factorisation in Z \mathbb{Z} does not contain an odd prime, congruent to 3 3 modulo 4 4 , which is repeated an odd number of times.

If n 6 ( m o d 8 ) n \equiv 6 \pmod{8} , then the prime factorisation of n n over Z \mathbb{Z} must contain an odd number of primes congruent to 3 3 modulo 4 4 , and this means that such numbers cannot be written as a sum of two squares. There are 12 12 such numbers between 1 1 and 100 100 : 6 6 , 14 14 , 22 22 , 30 30 , 38 38 , 46 46 , 54 54 , 62 62 , 70 70 , 78 78 , 86 86 , 94 94 .

If n 2 ( m o d 8 ) n \equiv 2 \pmod{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 42 = 2 × 3 × 7 42 = 2\times3\times7 and 66 = 2 × 3 × 11 66 = 2\times3\times11 .

Thus there are 12 + 2 = 14 12+2 = 14 numbers which cannot be written as either a difference or a sum of two squares, and hence there are 86 \boxed{86} numbers that can.

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 4m + 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.

Brian Charlesworth - 4 years, 1 month ago

A prime integer p N p \in \mathbb{N} is prime in: Z [ i ] \mathbb{Z}[i] if and only if: p 3 ( m o d 4 ) p \equiv 3 \pmod{4} ; Why ???

Kushal Bose - 4 years, 1 month ago

Log in to reply

If p p is a prime in Z \mathbb{Z} which is not prime in the Gaussian integers, it must be equal to z z = z 2 z\,\overline{z} =|z|^2 for some Gaussian integer z z , and so must be the sum of two square integers. The sum of two integer squares cannot be congruent to 3 3 modulo 4 4 , so primes p p that are congruent to 3 3 modulo 4 4 are prime in the Gaussian integers.

The fact that primes congruent to 1 1 modulo 4 4 are reducible in the Gaussian integers follows from the fact that 1 -1 is a quadratic residue modulo such primes.

Mark Hennings - 4 years, 1 month ago

Log in to reply

First part is okk

Can u elaborate for the 2nd part ?

Kushal Bose - 4 years, 1 month ago

Log in to reply

@Kushal Bose If p = 4 n + 1 p = 4n+1 is prime, use Wilson's Theorem to show that ( ( 2 n ) ! ) 2 1 ( m o d p ) ((2n)!)^2 \equiv -1 \pmod{p} . Thus 1 -1 is a quadratic residue modulo p p , and we can find an integer a a such that p p divides a 2 + 1 = ( a + i ) ( a i ) a^2+1 = (a + i)(a-i) . Since p p divides neither a + i a+i nor a i a - i , we deduce that p p cannot be prime in Z [ i ] \mathbb{Z}[i] .

Mark Hennings - 4 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...