Logic behind the code

i took help from the internet for the code but i am still unable to understand the logic behind the code for O(logn) complexity code.

Plz send your code by saving on ide