Normally, these three loops runs O(n) respectively, making the time complexity O(n2).
However, consider the second loop, where there is
If (gcd(i,j) == 1) {
j = n
}
Then, since there is gcd(i,j) == 1, the loop ends. Since the GCD of any two consecutive integer is 1, the second loop would always ends when j == i + 1. Thus, the second loop runs O(1) times only.
As a result, the time complexity isT(n) = O(n2)