Modify sequence of first N natural numbers to a given array by replacing pairs with their GCD | Java program for the above approach ; Function to check if array arr [ ] can be obtained from first N natural numbers or not ; Driver code ; Function Call
class GFG { static void isSequenceValid ( int [ ] B , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( ( i + 1 ) % B [ i ] != 0 ) { System . out . print ( " No " ) ; return ; } } System . out . print ( " Yes " ) ; } public static void main ( String [ ] args ) { int N = 4 ; int [ ] arr = { 1 , 2 , 3 , 2 } ; isSequenceValid ( arr , N ) ; } }