def _can_do_sum_of_squares(n, k):
 if (k < 1):
  return False
 if (n < 0):
  return False
 if (n == 0):
  return True
 if (k == 1):
  return is_square(n)
 if (k == 2):
  if (n in (1, 2)):
   return True
  if isprime(n):
   if ((n % 4) == 1):
    return 1
   return False
  else:
   f = factorint(n)
   for (p, m) in f.items():
    if (((p % 4) == 3) and (m % 2)):
     return False
   return True
 if (k == 3):
  if (((n // (4 ** multiplicity(4, n))) % 8) == 7):
   return False
 return True

def _can_do_sum_of_squares ( n , k ) : if ( k < 1 ) : return False if ( n < 0 ) : return False if ( n == 0 ) : return True if ( k == 1 ) : return is_square ( n ) if ( k == 2 ) : if ( n in ( 1 , 2 ) ) : return True if isprime ( n ) : if ( ( n % 4 ) == 1 ) : return 1 return False else : f = factorint ( n ) for ( p , m ) in f . items ( ) : if ( ( ( p % 4 ) == 3 ) and ( m % 2 ) ) : return False return True if ( k == 3 ) : if ( ( ( n // ( 4 ** multiplicity ( 4 , n ) ) ) % 8 ) == 7 ) : return False return True
return true if n can be written as the sum of k squares .