Print all numbers whose set of prime factors is a subset of the set of the prime factors of X | C # program to implement the above approach ; Function to print all the numbers ; Iterate for every element in the array ; Find the gcd ; Iterate till gcd is 1 of number and x ; Divide the number by gcd ; Find the new gcdg ; If the number is 1 at the end then print the number ; If no numbers have been there ; Driver code
using System ; class GFG { static void printNumbers ( int [ ] a , int n , int x ) { bool flag = false ; for ( int i = 0 ; i < n ; i ++ ) { int num = a [ i ] ; int g = __gcd ( num , x ) ; while ( g != 1 ) { num /= g ; g = __gcd ( num , x ) ; } if ( num == 1 ) { flag = true ; Console . Write ( a [ i ] + " ▁ " ) ; } } if ( ! flag ) Console . WriteLine ( " There ▁ are ▁ no ▁ such ▁ numbers " ) ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int x = 60 ; int [ ] a = { 2 , 5 , 10 , 7 , 17 } ; int n = a . Length ; printNumbers ( a , n , x ) ; } }