Check if the square of a number is divisible by K or not | Python3 implementation to check if the square of X is divisible by K ; Function to return if square of X is divisible by K ; Finding gcd of x and k ; Dividing k by their gcd ; Check for divisibility of X by reduced K ; Driver Code
from math import gcd NEW_LINE def checkDivisible ( x , k ) : NEW_LINE INDENT g = gcd ( x , k ) NEW_LINE k //= g NEW_LINE if ( x % k == 0 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 6 NEW_LINE k = 9 NEW_LINE checkDivisible ( x , k ) ; NEW_LINE DEDENT