text: Modify array such that the array does not contain any common divisors other than 1 | C # program for the above approach ; Function to check if it is possible to modify the array such that there is no common factor between array elements except 1 ; Stores GCD of the array ; Calculate GCD of the array ; If the current divisor is smaller than X ; Divide GCD by the current divisor ; If possible ; Print the modified array ; Otherwise ; Driver Code ; Given array ; Size of the array
code: using System ; using System . Collections . Generic ; class GFG { static int GCD ( int a , int b ) { return b == 0 ? a : GCD ( b , a % b ) ; } static void checkCommonDivisor ( int [ ] arr , int N , int X ) { int G = 0 ; for ( int i = 0 ; i < N ; i ++ ) { G = GCD ( G , arr [ i ] ) ; } int copy_G = G ; for ( int divisor = 2 ; divisor <= X ; divisor ++ ) { while ( G % divisor == 0 ) { G = G / divisor ; } } if ( G <= X ) { Console . WriteLine ( " Yes " ) ; for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] / copy_G + " ▁ " ) ; Console . Write ( " STRNEWLINE " ) ; } else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int [ ] arr = { 6 , 15 , 6 } ; int X = 6 ; int N = arr . Length ; checkCommonDivisor ( arr , N , X ) ; } }