/*****************************************************************************/
/*									     */
/*  COUNT PAIRS OF CONSECUTIVE ROOTS OF THE CONGRUENCE X**((P-1)/N)=Y(MOD P) */
/*  02/02/07 (dkc)							     */
/*									     */
/*****************************************************************************/
#include <math.h>
unsigned int r[];
unsigned int croots(unsigned int *input, unsigned int index, unsigned int n,
		    unsigned int *output) {
unsigned int p,p1,i,j,k;
p=input[2*index];		     // load prime
r[0]=input[2*index+1];		     // load primitive root
p1=p-1;
if (p1!=(p1/n)*n)		     // check if n divides p-1
   return(0);
for (i=0; i<n; i++)		     // clear output array
   output[i]=0;
for (i=1; i<p1; i++)		     // compute powers of primitive root
   r[i]=r[0]*r[i-1]-((r[0]*r[i-1])/p)*p;
if (r[p1-1]!=1) 		     // return if last power is not equal to 1
   return(2);
for (i=0; i<n; i++) {		     // compute roots of x**((p-1)/n)=y(mod p)
   for (j=i; j<p1; j+=n) {
      for (k=i; k<p1; k+=n) {
	 if ((r[j]-r[k])==1)	     // count consecutive roots
	    output[i]=output[i]+1;
	 }
      }
   }
return(1);
}