Computer Science, asked by Shubhadeep96, 1 year ago

A positive integer m can be expresseed as the sum of three squares if it is of the form p + q + r where p, q, r ≥ 0, and p, q, r are all perfect squares. For instance, 2 can be written as 0+1+1 but 7 cannot be expressed as the sum of three squares. The first numbers that cannot be expressed as the sum of three squares are 7, 15, 23, 28, 31, 39, 47, 55, 60, 63, 71, … (see Legendre's three-square theorem).

Write a Python function threesquares(m) that takes an integer m as input and returns True if m can be expressed as the sum of three squares and False otherwise. (If m is not positive, your function should return False.)

Here are some examples of how your function should work.
>>> threesquares(6)
True

>>> threesquares(188)
False

>>> threesquares(1000)
True

Please help!!

Answers

Answered by skumar85
0

Answer:

soorry i dont understand this answer

Answered by Anonymous
0

The python function threesquares(m) that takes an integer m as input and returns True if m can be expressed as the sum of three squares and False otherwise is as follows:

def threesquares(m):

       while m > 0 and m % 4 == 0:

              m /= 4

        return m % 8 != 7

for x in range(500):

        if not threesquares(m):

               print(x, end=' ,  ')

print( )

Similar questions