def prime_as_sum_of_two_squares(p):
 if (not ((p % 4) == 1)):
  return
 if ((p % 8) == 5):
  b = 2
 else:
  b = 3
  while (pow(b, ((p - 1) // 2), p) == 1):
   b = nextprime(b)
 b = pow(b, ((p - 1) // 4), p)
 a = p
 while ((b ** 2) > p):
  (a, b) = (b, (a % b))
 return (int((a % b)), int(b))

def prime_as_sum_of_two_squares ( p ) : if ( not ( ( p % 4 ) == 1 ) ) : return if ( ( p % 8 ) == 5 ) : b = 2 else : b = 3 while ( pow ( b , ( ( p - 1 ) // 2 ) , p ) == 1 ) : b = nextprime ( b ) b = pow ( b , ( ( p - 1 ) // 4 ) , p ) a = p while ( ( b ** 2 ) > p ) : ( a , b ) = ( b , ( a % b ) ) return ( int ( ( a % b ) ) , int ( b ) )
represent a prime p as a unique sum of two squares; this can only be done if the prime is congruent to 1 mod 4 .