Check if a number is divisible by all prime divisors of another number | CPP program to find if all prime factors of y divide x . ; Returns true if all prime factors of y divide x . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isDivisible ( int x , int y ) { if ( y == 1 ) return true ; if ( __gcd ( x , y ) == 1 ) return false ; return isDivisible ( x , y / gcd ) ; } int main ( ) { int x = 18 , y = 12 ; if ( isDivisible ( x , y ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }