On generating certain quadruples

48 Views Asked by At

As part of running simulations related to this question, I had to write a program that generates quadruples $(\alpha, \beta, a, b)$ such that

  1. $\alpha, \beta, a, b$ are all less than $n$ and
  2. $\gcd(\alpha, n) = \gcd(\beta, n) = \gcd(a, n) = \gcd(b, n) = 1$ and
  3. $\gcd(\alpha b - \beta a, n) = 1$

and $n$ is an odd integer.

The brute-force method I use is given in pseudocode below:

for alpha = 1 to n-1
   if(gcd(alpha, n) == 1)
     for beta = alpha+1 to n-1
       if(gcd(beta, n) == 1)
         for a = beta+1 to n-1
           if(gcd(a, n) == 1)
             for b = a+1 to n
               if(gcd(b, n) == 1)
                  if(gcd(alpha*b - beta*a, n) == 1)
                    yield (alpha, beta, a, b)
                  end if
               end if
             next
           end if
         next
       end if
     next
   end if
next

Is there a more efficient way to generate these quadruples?