Find the total number of integers between 2000 and 2099 inclusive that can be represented as the sum of two perfect squares of two positive integers in at least two different ways.
For example, 8 5 = 7 2 + 6 2 = 9 2 + 2 2 .
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.
A brute force solution (python):
sumlist = []
for a in range(1,2100):
for b in range(1,2100):
if 2000<=a**2+b**2<=2099:
sumlist.append(a**2+b**2)
a=[]
for i in sumlist:
if sumlist.count(i)>=4:
a.append(i)
print (len(set(a)))
You got lucky. Consider the number 5 0 = 7 2 + 1 2 = 5 2 + 5 2 If there had been a number in the range 2 0 0 0 to 2 0 9 9 like 5 0 , in that it could be written as the sum of the squares of two integers in two different ways, but where one of those ways was of the form a 2 + a 2 , then your code would have given a "sumlist.count" of 3 for that number, and not found it...
Log in to reply
I shall make the necessary edits to my code. Thanks for piinting it out.
Log in to reply
Iterate b fin range(a,2100), and look for sumlist.count >= 2 (i.e. cut out repetitions of the same answer).
Problem Loading...
Note Loading...
Set Loading...
Relevant wiki: Gaussian Integers
The primes in the Gaussian integers are:
and their associates. An integer N can be written as the sum X 2 + Y 2 of two positive integers if N can be written as ( X + i Y ) ( X − i Y ) in the Gaussian integers. Since 2 = ( 1 + i ) ( 1 − i ) , any power of 2 can be so written. Similarly, any power of a prime integer congruent to 1 modulo 4 can be so written, but prime integers congruent to 3 modulo 4 cannot. Thus N can only be written as a sum of two squares when prime integers congruent to 3 modulo 4 occur an even number of times in the prime decomposition of N . There are 3 0 numbers between 2 0 0 0 and 2 0 9 9 inclusive with this property.
Since 1 + i and 1 − i are associate, ( 1 + i ) m divides X + i Y precisely when ( 1 − i ) m divides X − i Y . Thus, if 2 m is a factor of N , we must have ( 1 + i ) m as a factor of X + i Y , so powers of 2 do not give us any flexibility in the choice of X + i Y .
To be able to write N as a sum of two squares in at least two different ways, N must contain at least 2 prime factors which are congruent to 1 modulo 4 (these prime factors could be repeated). There are 9 numbers which satisfy all conditions so far: 2 0 0 0 , 2 0 0 5 , 2 0 2 0 , 2 0 2 5 , 2 0 4 1 , 2 0 4 5 , 2 0 5 0 , 2 0 7 4 , 2 0 8 0 Of these, all but two have two different odd prime factors, and so certainly can be written as a sum of square positive integers in least two different ways. The remaining two cases are:
Thus there are 8 possible numbers.