Check if the square of a number is divisible by K or not | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkDivisible ( int x , int k ) { int g = __gcd ( x , k ) ; k /= g ; if ( x % k == 0 ) { cout << " YES STRNEWLINE " ; } else { cout << " NO STRNEWLINE " ; } } int main ( ) { int x = 6 , k = 9 ; checkDivisible ( x , k ) ; return 0 ; }