Difference of Squares

How many of the integers between 1 and 1000, inclusive, can be expressed as the difference of the squares of two non-negative integers?


The answer is 750.

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.

6 solutions

Zach Abueg
Jan 8, 2017

We want to know the number of integers x x which can be written as

x = a 2 b 2 x = a^2 - b^2

Let's break this up and look at two sets of numbers: odd and even.

If x x is an odd number, it can be written as 2 n + 1 2n + 1 . Now consider the number ( n + 1 ) 2 (n + 1)^2 , or n 2 + 2 n + 1 n^2 + 2n + 1 . We can use that to express 2 n + 1 2n + 1 in a different way.

2 n + 1 = ( n + 1 ) 2 n 2 2n + 1 = (n + 1)^2 - n^2

This proves that every odd number can be written as the difference of two squares. In fact, adjacent squares are separated by successive odd numbers.

Now let's account for the even numbers. First, we know that a 2 b 2 = ( a + b ) ( a b ) a^2 - b^2 = (a + b)(a - b) . Let's consider 3 cases relating to the parity of a a and b : b: a a and b b are both even, both odd, or one of each.

Both even : : a ± b a \pm b is even, ( a + b ) ( a b ) (a + b)(a - b) is even

Both odd : : a ± b a \pm b is even, ( a + b ) ( a b ) (a + b)(a - b) is even

Even, odd : : a ± b a \pm b is odd, ( a + b ) ( a b ) (a + b)(a - b) is odd

We can ignore the last option, since we've already taken care of the odd numbers.

Any product of two even numbers has to be divisible by 4 4 - this is because the product will have at least two 2 2 s in its prime factorization. But the even numbers that cannot be evenly divided by 4 2 , 6 , 10 , 4 - 2, 6, 10, and so on - cannot be expressed as the product of two even numbers. These numbers therefore cannot be expressed in the form ( a + b ) ( a b ) , (a + b)(a - b), which also means that they cannot be expressed as the difference of two squares.

But is the converse - that all the even numbers divisible by 4 4 can be expressed as the difference of two squares - necessarily true? Yes, because if x x is a multiple of 4 , 4, it equals 4 n 4n for some number n n .

4 n 4n can be rewritten as: ( n + 1 ) 2 ( n 1 ) 2 . (n + 1)^2 - (n - 1)^2.

Thus, half of all the even numbers (those divisible by 4 4 ) can be expressed as the difference of two squares. The first 1 , 000 1,000 integers contain 500 500 even numbers, so half of those, plus all the odd numbers, can be expressed as a difference of two squares.

250 + 500 = 750 250 + 500 = 750

Actually the answer is 748 because 1 and 4 cannot be expressed as the difference of the squares of two positive integers, because 0 is not a positive integer.

Freddie Hand - 4 years, 5 months ago

Log in to reply

Good catch - I edited the question to convey the original intent.

Zach Abueg - 4 years, 5 months ago

Log in to reply

@Freddie Hand Great eye for detail! Those who answered 748 have been marked correct :)

In future, if you notice such errors, you can report the problem directly by selecting that option in the menu.

Calvin Lin Staff - 4 years, 5 months ago
Anirudh Sreekumar
Jan 23, 2017

( n + 1 ) 2 n 2 = 2 n + 1 (n+1)^2-n^2=2n+1 ,

thus every odd integer can be expressed as difference between 2 sqares

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

thus every multiple of 4 can be expressed as difference between 2 sqares

now, we need to prove that 2 ( 2 n + 1 ) 2(2n+1) cannot be expressed as difference between 2 squares

Assume, 2 ( 2 n + 1 ) 2(2n+1) can be expressed as difference between 2 squares

2 ( 2 n + 1 ) = a 2 b 2 = ( a + b ) ( a b ) 2(2n+1)=a^2-b^2=(a+b)(a-b)

now (a+b) and (a-b) will have the same parity i.e,they will both be even or they will both be odd

CASE 1: Assume they are odd

( a + b ) ( a b ) ( 2 n + 1 ) = 2 \dfrac{(a+b)(a-b)}{(2n+1)}=2 which has no solution

CASE 2: Assume they are even

( a + b ) ( a b ) ( 2 ) = 2 n + 1 \dfrac{(a+b)(a-b)}{(2)}=2n+1 ,which has no solution since LHS is always even

Thus our initial assumption is wrong and 2 ( 2 n + 1 ) 2(2n+1) cannot be expressed as difference between 2 squares

There are 500 500 odd numbers between 1 1 an 1000 1000 , and 250 250 multiples of 4 4 , thus the required answer is

500 + 250 = 750 500+250=\boxed{750}

Ashish Gupta
Feb 8, 2017

Peter Macgregor
Jan 23, 2017

For variety's sake I've decided to post a solution showing my actual path to the answer, rather than a boiled down, sanitised version. I hope you like it.

Every difference of two squares can be factorised like this

a 2 b 2 = ( a b ) ( a + b ) ( 1 ) a^2-b^2=(a-b)(a+b) \dots(1)

and for our problem a and b are integers and 0 b a 0 \leq b \leq a

Suppose first of all that a b = 1 a-b=1 so that a = b + 1 a=b+1 . Then in equation (1) we have

a 2 b 2 = ( 1 ) ( b + 1 + b ) = 2 b + 1 a^2-b^2=(1)(b+1+b)=2b+1

For b = 0 , 1 , 2 b=0,1,2 \dots the right hand side of this equation becomes 1 , 3 , 5 1,3,5 \dots and so we see that every positive odd integer is the difference of two squares. It is fun to confirm this with some specific examples -

1 = 1 2 0 2 3 = 2 2 1 2 5 = 3 2 2 2 1=1^2-0^2\\3=2^2-1^2\\5=3^2-2^2 \dots

Now let's suppose that a b = 2 a-b=2 so that a = b + 2 a=b+2 . Then in equation (1) we have

a 2 b 2 = ( 2 ) ( b + 2 + b ) = 2 ( 2 b + 2 ) = 4 ( b + 1 ) a^2-b^2=(2)(b+2+b)=2(2b+2)=4(b+1)

Now for b = 0 , 1 , 2 b=0,1,2 \dots the right hand side of this equation becomes 4 , 8 , 12 4,8,12 \dots and so we see that every positive multiple of 4 is the difference of two squares. Again it is nice to confirm this with specific examples, to make sure we are not barking up the wrong tree -

4 = 2 2 0 2 8 = 3 2 1 2 12 = 4 2 2 2 4=2^2-0^2\\8=3^2-1^2\\12=4^2-2^2 \dots

At this point I could intuit the solution: between 1 and 1000, all the 500 odd numbers and all the 250 multiples of four can be expressed as differences of two squares, making 750 \boxed{750} in all.

To make the solution complete we have to make clear why none of the other even numbers can be expressed as the difference of two squares. We can do this by showing that if a 2 + b 2 a^2+b^2 is even it is necessarily a multiple of 4.

Notice that ( a b ) (a-b) and ( a + b ) (a+b) have the same parity (by which I mean oddness or evenness) because their difference is 2 b 2b which is even. Then from equation 1 we see that a 2 + b 2 a^2+b^2 can be even only if ( a b ) (a-b) and ( a + b ) (a+b) are both even, which forces a 2 + b 2 a^2+b^2 to be a multiple of 4.

Jesse Nieminen
Jan 23, 2017

Clearly, every odd positive integer can be expressed as ( n + 1 ) 2 n 2 = 2 n + 1 \left(n+1\right)^2 - n^2 = 2n+1 for a non-negative integer n n .
Now, since all odd positive integers can be expressed as difference of two non-negative squares, by multiplying both squares by 4 4 they remain as squares and produce every positive integer divisible by 4 4 .
Also, since squares of non-negative integers are always, 0 0 or 1 1 modulo 4 4 , we trivially know that a difference of two non-negative squares is never congruent to 2 2 modulo 4 4 .

Hence, all odd numbers and numbers divisible by 4 4 can be and all others can't be expressed as difference of two non-negative squares.

Thus, the answer must be 750 \boxed{750} .

Kushal Bose
Jan 9, 2017

a 2 b 2 = n a^2-b^2=n where a , b Z + a,b \in Z^+ and 1 n 1000 1 \leq n \leq 1000

( a + b ) ( a b ) = n (a+b)(a-b)=n .Here ( a + b ) (a+b) and ( a b ) (a-b) should be both odd or both even.If a there is only one factor of two in the whole number then if u factorise any ways there will be one even factor and one odd factor .As their parity is different that's why there will be no a,b..Now, we will find such n n .Our rquire will looks like n = 2 × 3 a 1 × 5 a 2 × n=2 \times 3^{a_1} \times 5 ^{a_2} \times \cdots .This n s n's can be found just multiplying 2 2 with a odd integer.

So, maximum n = 2 m < 1000 = 998 m 499 n=2m<1000 =998 \implies m \leq 499 . i.e. 1 , 3 , 5 , 7 , . . . . , 499 1,3,5,7,....,499 .There are 250 250 numbers are there.

Therefore, required number of n = 1000 250 = 750 n=1000-250=750

The crux of the problem is to explain why "if n is comprised of only one factor of two, then it is not possible to find a, b". Can you elaborate on that?

The information of "n will look like 2 × 3 a 1 × 5 a 2 2 \times 3^{a_1} \times 5 ^ { a_2 } \ldots " seems irrelevant. There are much better ways of showing that there are 250 numbers which are multiple of 2 and not 4.

Calvin Lin Staff - 4 years, 5 months ago

Log in to reply

If a there is only one factor of two in the whole number then if u factorise any ways there will be one even factor and one odd factor .As their parity is different that's why there will be no a,b.

Yes I agree there is a better way to find the number of integers which is only multiple of two not four but at hat moment I got that idea

Kushal Bose - 4 years, 5 months ago

Log in to reply

As always, steps / explanations like this should be included in the solution directly. Not everyone is a mind reader who knows exactly what you are saying. They can only read what you wrote, to try and understand what you're thinking.

If you bear this in mind, that would greatly help with your solutions. A lot of times you miss out such steps. Sometimes they are minor and can be subsequently edited in, sometimes they are major and impact the entire solution.


As another example, you ignored the impact of "positive integers" vs "non-negative integers" in your solution. In the previous version, we should also have a step to explain why these values a , b a, b are positive integers, in which case you would have realized that the answer was not 750.

Calvin Lin Staff - 4 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...