• + 3 comments

    actually for both of the steps 1 & 2 the complexity will be O(n log(b)).

    Here n is the length of the array and b is the smaller integer of a pair(a,b) for which we calculate the GCD/LCM.

    For simplicity we call it O(n log(n)) instead of O(n log(b)).

    Explanation: To calculate the GCD or LCM for the whole array we need to run a loop up to the length of the array which is n and inside that loop we need to calculate GCD/LCM which will take log(n). like below.

    previousGCD = array[0];
    for(int i = 1; i<n; i++) {// n
    	previousGCD = GCD(previousGCD, array[i]);//log(n) 
    }
    

    so the complexity is O(n*log(n)). Same goes for LCM also.