@@ -314,7 +314,8 @@ static bool gtAbsVal(long a, long b)
314314
315315// Returns in gens a generating set for Zm* /<p>, and in ords the
316316// order of these generators. Return value is the order of p in Zm*.
317- long findGenerators (vector<long >& gens, vector<long >& ords, long m, long p)
317+ long findGenerators (vector<long >& gens, vector<long >& ords, long m, long p,
318+ const vector<long >& candidates)
318319{
319320 gens.clear ();
320321 ords.clear ();
@@ -333,20 +334,28 @@ long findGenerators(vector<long>& gens, vector<long>& ords, long m, long p)
333334 // The order of p is the size of the equivalence class of 1
334335#if 0
335336 long ordP = std::count(classes.begin(), classes.end(), 1);
336- // count(from,to,val) returns # of elements in (from,to) with value=val
337+ // count(from,to,val) returns # of elements in (from,to) with value=val
337338#else
338- long ordP = 0 ;
339- for (long i = 0 ; i < lsize (classes); i++)
340- if (classes[i] == 1 ) ordP++;
339+ long ordP = 0 ;
340+ for (long i = 0 ; i < lsize (classes); i++)
341+ if (classes[i] == 1 ) ordP++;
341342#endif
342343
343- // Compute orders in (Z/mZ)^*/<p> while comparing to (Z/mZ)^*
344+ // Compute orders in (Z/mZ)^* /<p> while comparing to (Z/mZ)^*
345+ long candIdx=0 ;
344346 while (true ) {
345347 compOrder (orders,classes,true ,m);
346348 // if the orders of i in Zm* /<p> and Zm* are not the same, then
347349 // order[i] contains the order in Zm* /<p> with negative sign
348350
349- long idx = argmax (orders, >AbsVal); // find the element with largest order
351+ long idx=0 ;
352+ if (candIdx<lsize (candidates)) { // try next candidate
353+ idx = candidates[candIdx++];
354+ if (abs (orders[idx])<=1 )
355+ idx=0 ;
356+ }
357+ if (idx==0 ) // no viable candidates supplied externally
358+ idx = argmax (orders, >AbsVal);// find the element with largest order
350359 long largest = orders[idx];
351360
352361 if (abs (largest) == 1 ) break ; // Trivial group, we are done
0 commit comments