Expressing a Number as a Sum/Difference of Two Squares
Quantitative Aptitude › Number System · Topic 1.20
A positive integer can be written as a difference of two squares exactly when it is odd or divisible by 4, because a2 - b2 = (a - b)(a + b). It can be written as a sum of two squares exactly when every prime of the form 4k + 3 in it has an even exponent.
6 min read · Quantitative Aptitude · Number System
Quick Answer
A positive integer can be written as a difference of two squares exactly when it is odd or divisible by 4, because a2 – b2 = (a – b)(a + b). It can be written as a sum of two squares exactly when every prime of the form 4k + 3 in it has an even exponent.
At a Glance
- Difference of squares a2 – b2 = (a – b)(a + b)
- Possible if Number is odd or a multiple of 4
- Not possible if Number leaves remainder 2 on division by 4
- Sum of two squares 4k + 3 primes need even exponents
- 45 as a difference 72 – 22, 92 – 62, 232 – 222
- 65 as a sum 82 + 12, 72 + 42
Where Does It Fit?
This topic closes the Number System macro after Highest Power of a Prime Number Dividing a Factorial and uses the identities that macro Basic Algebraic Identities (a+b, a-b, a²-b² and Related Expansions) will state formally. It ties together factors from Number of Factors, Sum of Factors and Product of Factors of a Number and squares from Perfect Numbers, Perfect Squares and Perfect Cubes Identification.
When Is a Number a Difference of Two Squares?
In short: write n = (a – b)(a + b). The two factors have the same parity, so n is odd or a multiple of 4.
Conditions
- If n is odd, n = 2k + 1 = (k + 1)2 – k2.
- If n = 4k, then n = (k + 1)2 – (k – 1)2.
- If n leaves remainder 2 on division by 4 (2, 6, 10, 14, 18, …), it cannot be written as a difference of two squares.
| n | Factor pairs of the same parity | Representations a2 – b2 |
|---|---|---|
| 45 | 1 × 45, 3 × 15, 5 × 9 | 232 – 222, 92 – 62, 72 – 22 |
| 60 | 2 × 30, 6 × 10 | 162 – 142, 82 – 22 |
| 15 | 1 × 15, 3 × 5 | 82 – 72, 42 – 12 |
| 30 | none | Not possible |
To list all ways, take each factor pair (d, e) with d < e and both odd or both even; then a = (d + e)/2 and b = (e – d)/2. The numbers up to 20 that cannot be written as a difference of two squares are 2, 6, 10, 14 and 18.
When Is a Number a Sum of Two Squares?
In short: by Fermat’s two-square theorem, n is a sum of two squares if and only if every prime of the form 4k + 3 divides n an even number of times.
- 65 = 5 × 13, and both primes are of the form 4k + 1, so 65 = 82 + 12 = 72 + 42.
- 50 = 2 × 52 = 72 + 12 = 52 + 52.
- 21 = 3 × 7, and both 3 and 7 are of the form 4k + 3 with odd exponents, so 21 is not a sum of two squares.
- 45 = 32 × 5, with 3 appearing twice, so 45 = 62 + 32.
- The numbers up to 30 that are sums of two positive squares are 2, 5, 8, 10, 13, 17, 18, 20, 25, 26 and 29.
How Does the Product of Two Sums of Squares Work?
In short: the product of two sums of two squares is itself a sum of two squares, by Brahmagupta’s identity.
Brahmagupta identity
- (a2 + b2)(c2 + d2) = (ac – bd)2 + (ad + bc)2 = (ac + bd)2 + (ad – bc)2
For 5 = 22 + 12 and 13 = 32 + 22, the first form gives (6 – 2)2 + (4 + 3)2 = 42 + 72 = 65, and the second form gives (6 + 2)2 + (4 – 3)2 = 82 + 12 = 65. This is why 65 has two representations. Other algebraic identities are collected in Basic Algebraic Identities (a+b, a-b, a²-b² and Related Expansions).
Solved Examples
Example 1
Question: Express 45 as a difference of two squares in all possible ways.
- Factor pairs of 45 with the same parity (both odd): 1 × 45, 3 × 15, 5 × 9.
- For (1, 45): a = 23, b = 22. For (3, 15): a = 9, b = 6. For (5, 9): a = 7, b = 2.
- Check: 529 – 484 = 45, 81 – 36 = 45, 49 – 4 = 45.
Answer: 3 ways: 232 – 222, 92 – 62, 72 – 22.
Example 2
Question: Express 60 as a difference of two positive squares.
- 60 is a multiple of 4. Both factors must be even: 2 × 30 and 6 × 10.
- For (2, 30): a = 16, b = 14. For (6, 10): a = 8, b = 2.
- Check: 256 – 196 = 60 and 64 – 4 = 60.
Answer: 162 – 142 and 82 – 22.
Example 3
Question: Can 30 be written as a difference of two squares?
- 30 leaves remainder 2 on division by 4.
- Its factor pairs 1 × 30, 2 × 15, 3 × 10 and 5 × 6 all have mixed parity.
Answer: No.
Example 4
Question: Write 65 as a sum of two squares in two ways.
- 65 = 5 × 13. Use the identity or trial.
- 65 – 1 = 64 = 82, giving 82 + 12.
- 65 – 16 = 49 = 72, giving 72 + 42.
Answer: 65 = 82 + 12 = 72 + 42.
Example 5
Question: Is 21 a sum of two squares?
- 21 = 3 × 7, and both primes leave remainder 3 on division by 4 with exponent 1.
- Check by subtraction: 21 – 1 = 20, 21 – 4 = 17, 21 – 9 = 12, 21 – 16 = 5. None is a square.
Answer: No.
Shortcuts and Tricks
- A number leaving remainder 2 on division by 4 is never a difference of two squares.
- For an odd number n, use ((n + 1)/2)2 – ((n – 1)/2)2.
- List factor pairs of the same parity to find all representations.
- For sums, factorize and check the 4k + 3 primes.
- Use Brahmagupta’s identity to build sums from smaller ones.
Common Mistakes
- Using factor pairs of different parity.
- Forgetting that b may be zero when the number itself is a perfect square.
- Assuming every number is a sum of two squares.
- Counting (a, b) and (b, a) as different sums.
- Misreading primes of the form 4k + 1 as 4k + 3.
Practice Questions
- How many ways can 105 be written as a difference of two positive squares?
- How many ways can 1,001 be written as a difference of two positive squares?
- Write 15 as a difference of two squares.
- Is 3 a sum of two squares?
- Write 13 as a sum of two squares.
- Which numbers from 1 to 20 are not a difference of two squares?
Answers: 1) 4; 2) 4; 3) 82 – 72; 4) no; 5) 32 + 22; 6) 2, 6, 10, 14, 18.
Why Is This Topic Important?
- Factor skill Strengthens factor pair thinking.
- Exam use Appears in number theory and algebra puzzles.
- Link Uses squares from Perfect Numbers, Perfect Squares and Perfect Cubes Identification.
- Link Identity at Basic Algebraic Identities (a+b, a-b, a²-b² and Related Expansions).
What Comes Next?
The next macro is HCF, LCM and Divisibility Rules, which begins with Highest Common Factor (HCF) by Division and Prime Factorization Method on finding the highest common factor.
Key Terms and Formulas
- Difference of squares a2 – b2
- Parity Being odd or even
- Factor pair Two factors with product n
- 4k + 3 prime A prime leaving remainder 3 on division by 4
- Brahmagupta identity Product of sums of squares
- Representation One way of writing a number
Related Topics
- Highest Power of a Prime Number Dividing a Factorial
- Classification of Numbers (Natural, Whole, Integers, Rational, Irrational and Real Numbers)
- Face Value and Place Value of Digits
- Divisibility Rules for 2 to 19
Exam Corner
Points to Remember
- a2 – b2 = (a – b)(a + b); both factors have the same parity.
- Possible for odd numbers and multiples of 4; impossible for 2 mod 4.
- Sum of two squares: 4k + 3 primes need even exponents.
- 65 = 82 + 12 = 72 + 42.
- 45 has 3 representations as a difference of squares.
Do Not Confuse With
- Sum vs difference of squares Different conditions apply.
- 4k + 1 vs 4k + 3 primes 4k + 3 primes need even exponents for a sum of two squares.
- Parity of factors Both factors must be odd or both even.
- Representation vs order (a, b) and (b, a) give the same sum of squares.
Memory Hook
Same-parity pairs for a difference; fours and threes for a sum.
GS Relevance
Frequently Asked Questions
When can a number be written as a difference of two squares?
A positive integer can be written as a difference of two squares exactly when it is odd or a multiple of 4. Numbers that leave remainder 2 on division by 4, such as 2, 6 and 30, cannot be written this way, because the factors of a squares difference must have the same parity.
How do you find all ways to write a number as a difference of two squares?
To find all ways, list the factor pairs of the number where both factors are odd or both are even, then for each pair d and e compute a as half the sum and b as half the difference. For 45, the pairs 1 and 45, 3 and 15, 5 and 9 give three representations.
When is a number a sum of two squares?
By Fermat's two-square theorem, a positive integer is a sum of two squares if and only if every prime of the form 4k plus 3 divides it an even number of times. For example, 65 equals 8 squared plus 1 squared, while 21 is not a sum of two squares.
What is Brahmagupta's identity?
Brahmagupta's identity states that the product of two sums of two squares is again a sum of two squares: a squared plus b squared times c squared plus d squared equals ac minus bd all squared plus ad plus bc all squared. It shows why 5 times 13, which is 65, can be written as 4 squared plus 7 squared.
Is every odd number a difference of two squares?
Yes, every odd number is a difference of two squares. An odd number 2k plus 1 equals k plus 1 all squared minus k squared. For example, 15 equals 8 squared minus 7 squared, since 64 minus 49 is 15, so the representation always exists for odd numbers.
PYQ Practice — Statement Analysis
1 The number 30 can be written as a difference of two squares.
30 leaves remainder 2 on division by 4, so no representation exists.
2 Every odd number is a difference of two squares.
2k + 1 = (k + 1)2 - k2.
3 The number 21 is a sum of two squares.
3 and 7 are 4k + 3 primes with odd exponents.
4 The number 65 can be written as a sum of two squares in two ways.
65 = 82 + 12 = 72 + 42.
Related Topics
Browse the full Quantitative Aptitude index