Creating inputs that make a subtraction-based GCD algorithm slow

33 Views Asked by At

I have a GCD algorithm that is based on comparison and subtraction. The principle looks like this:

while a != b
    while (a > b)
        n = 1
        while (a > pow(b, n))
            a = a - pow(b, n)
            n = n + 1
    swap a with b 

I want to specifically find some numbers that makes the algorithm slow (number of loops run). For example, $5$ and $15$ makes the algorithm very fast, while $2^{15}$ and $1$ makes it slow, but $2^{15}-1$ and $2^{13}-1$ makes it even slower. However, randomly-generated numbers like $30533$ and $19015$ can be slowest, among what numbers I have now.

Is there an algorithm that can find (or better, calculate) a pair of number that makes the above GCD algorithm slow, with both numbers under a given cap. In my case, I need the numbers to be smaller than (not equal to) $2^{15}$ (or $32768$).

Enumerating is not an option for me because profiling the algorithm in my environment is very slow, also if the cap gets bigger, enumerating is impractical.