Блог пользователя valeriu

Автор valeriu, история, 17 месяцев назад, По-английски

Hello codeforces,

Today, I am regretably in math class with the subject of modular arithmetic. While thinking about a problem, I reminded myself of a question I asked myself some time ago.

Given $$$p$$$ and $$$mod$$$, find a $$$q$$$ such that $$$q^2$$$ = $$$p$$$ (modulo $$$mod$$$). $$$mod$$$ is prime and ≫ $$$10^8$$$

Does this admit an online logarithmic-complexity solution?

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится +9 Проголосовать: не нравится

Yes, if you're fine with randomized approaches. See #8 here.

By the way, if $$$m \equiv 3 \pmod 4$$$, you can compute it as $$$q \equiv p^{\frac{m+1}{4}} \pmod{m}$$$ (see here).

»
17 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Yes. The Tonelli-Shanks algorithm does it in logarithmic time. For an explanation, I think the Wikipedia article is straightforward enough.