Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор SHAMPINION, история, 6 лет назад, По-русски

It's obvious that $$$l = k \cdot x + c$$$, where $$$c$$$ is one of the {$$$a + b, a - b, -a + b, -a - b$$$}(if c < 0, let's increase it by $$$k$$$).

Now we have to find maximum and minimum $$$q > 0$$$ such that $$$q \cdot l \equiv 0$$$(mod $$$n \cdot k$$$).

Finding maximum is quite easy and not really interesting so I will stop on the second problem.

let $$$d = gcd(k, c)$$$. Let's forget about multiplier $$$q$$$, we will add it in formulas a few later.

$$$d \cdot (k' \cdot x + c') \equiv 0$$$(mod $$$n \cdot k$$$)

let $$$rem = \frac{n \cdot k} {gcd(n \cdot k, d)}$$$, $$$x = c' \cdot y$$$(we can choose any $$$x$$$ from $$$[1; \infty]$$$ so let it divide $$$c'$$$)

$$$c' \cdot (k' \cdot y + 1) \equiv 0$$$(mod $$$rem$$$)

Again let $$$rem' = \frac{rem}{gcd(rem, c')}$$$

$$$k' \cdot y + 1 \equiv 0$$$(mod $$$rem'$$$)

If $$$gcd(k', rem') = d' > 1$$$, this equation has no solutions(because $$$k' \cdot y$$$ is multiple by $$$d$$$, and 1 isn't). So our aim is to choose such minimal $$$q$$$ that $$$gcd(k', rem' / s) = 1$$$(choosing $$$s$$$ aliquant by $$$rem'$$$ is meaningless).

To get $$$gcd(k', rem' / s) = 1$$$, we should divide $$$rem'$$$ by all prime $$$p$$$ that divide $$$k'$$$. We can do that in $$$O(\sqrt k')$$$. As $$$k' <= k$$$, total complexity is $$$O(\sqrt k)$$$(or we can use Pollard's p − 1 algorithm and reach $$$O(\sqrt[4]k)$$$

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

»
6 лет назад, # |
  Проголосовать: нравится +29 Проголосовать: не нравится

But it's hard to code on the round)))

»
6 лет назад, # |
Rev. 2   Проголосовать: нравится -14 Проголосовать: не нравится

Actually I also solved that problem in $$$O(\sqrt k)$$$