Find numbers in range [ L , R ] that are coprime with given Array elements | C # program for the above approach ; Function to find all the elements in the range [ L , R ] which are co prime with all array elements ; Store all the divisors of array element in S ; Find the divisors ; Stores all possible required number satisfying the given criteria ; Insert all element [ L , R ] ; Traverse the set ; Remove the multiples of ele ; Print the resultant numbers ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static void elementsCoprimeWithArr ( int [ ] A , int N , int L , int R ) { HashSet < int > S = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int curr_ele = A [ i ] ; for ( int j = 1 ; j <= Math . Sqrt ( curr_ele ) + 1 ; j ++ ) { if ( curr_ele % j == 0 ) { S . Add ( j ) ; S . Add ( curr_ele / j ) ; } } } HashSet < int > store = new HashSet < int > ( ) ; for ( int i = L ; i <= R ; i ++ ) store . Add ( i ) ; S . Remove ( 1 ) ; foreach ( int it in S ) { int ele = it ; int index = 1 ; while ( index * ele <= R ) { store . Remove ( index * ele ) ; index ++ ; } } foreach ( int i in store ) { Console . Write ( i + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 5 } ; int L = 1 , R = 10 ; int N = arr . Length ; elementsCoprimeWithArr ( arr , N , L , R ) ; } }