human
What is a code to check whether a number can be represented by sum of two squares and the other steps required given the following:
Check whether a number can be represented by sum of two squares | Check whether a number can be represented by sum of two squares using Fermat Theorem ..
Count all the prime factors ..
Ifany prime factor of the form ( 4 k + 3 ) ( 4 k + 3 ) occurs an odd number of times ..
If n itself is a x prime number and can be expressed in the form of 4 k + 3 we return false ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check whether a number can be represented by sum of two squares and the other steps required.
 def judgeSquareSum ( n ) :
	i = 2 ;
	while ( i * i <= n ) :
		count = 0 ;
		if ( n % i == 0 ) :
			while ( n % i == 0 ) :
				count += 1 ;
				n = int ( n / i ) ;
			if ( i % 4 == 3 and count % 2 != 0 ) :
				return False ;
		i += 1 ;
	return n % 4 != 3 ;
n = 17 ;
if ( judgeSquareSum ( n ) ) :
	print ( " Yes " ) ;
else :
	print ( " No " ) ;