now if n is itself a prime so it will be present in primes array and here we have to find nearest prime less than n so we will return primes [ mid - 1 ]
if ( $ primes [ $ mid ] == $ n ) return $ primes [ $ mid - 1 ] ;