There is a bounded-error quantum algorithm that, on input , outputs the unique with using a number of gates polynomial in (dominated, as in factoring, by modular exponentiation).
The function on satisfies exactly when is a multiple of : it hides the subgroup generated by . Evaluating in superposition, applying Fourier transforms to both registers and measuring yields pairs satisfying a linear relation with , from which is computed classically. This is due to Shor; Kitaev placed it, with factoring, in the abelian stabilizer (hidden subgroup) framework. The same approach works for any finite abelian group with efficiently computable, uniquely represented elements; for elliptic-curve groups over prime fields the circuits were worked out by Proos and Zalka and costed in detail by Roetteler, Naehrig, Svore and Lauter.