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

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

Recently I wrote my very first problem (that was $$$>$$$ D2A and not just a standard application of an algorithm) that I both wrote and solved myself.

Link: https://mirror.codeforces.com/gym/104669/problem/L

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

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

Auto comment: topic has been updated by skye_ (previous revision, new revision, compare).

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

Auto comment: topic has been updated by skye_ (previous revision, new revision, compare).

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

Great d2E level problem. Anyone reading should try it out :)

»
13 месяцев назад, # |
  Проголосовать: нравится -21 Проголосовать: не нравится

"guys give me contribution"

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

orz

  • »
    »
    13 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    nou

    I still don't understand how you solved for $$$O(a^{\frac{3}{4}} + \text{factorization}(R))$$$.

    • »
      »
      »
      13 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      That sounds interesting, I only have $$$O(a + \sqrt{b})$$$ solution.

      • »
        »
        »
        »
        13 месяцев назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        I think his idea was something along the lines of 'we probably don't have to check that many factors if we check from greatest to least and break once we find one that works' so instead of checking each of $$$b - 1$$$ intervals, he instead checked each factor $$$f$$$ in $$$O(\frac{R}{f})$$$ because if the factors are big, this will take less time and somehow found a bound on the number of factors we have to check but I didn't completely understand what he did.

        Btw if you want to, could you share your solution/if you liked the problem?

        • »
          »
          »
          »
          »
          13 месяцев назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          My optimisation is based on the fact that if we look at values we can get by using $$$b/2$$$ elements, the length of this segment of values will be $$$\frac{b^2}{4}$$$ (roughly). So for any number less than that we surely have something divisible by it inside this segment. So we only need to check divisors that are greater than $$$\frac{b^2}{4}$$$. $$$R = \frac{b(2a+b-1)}{2} = O(b(a+b))$$$. Let's enumerate big divisors of $$$R$$$ by trying $$$\frac{R}{k}$$$ for small integer $$$k$$$. We can see that we only need to iterate over $$$\frac{4R}{b^2} = O(\frac{a}{b} + 1)$$$ values of $$$k$$$. Since checking each one of them takes $$$O(b)$$$ time, we can check all in $$$O(a+b)$$$.

          The problem is nice.

        • »
          »
          »
          »
          »
          13 месяцев назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          We also don't need to check any divisors less than $$$a+\frac{b-1}{2}$$$: put $$$a$$$ and $$$a+b-1$$$ in the first set, and the rest in the second set, which immediately gives that as the GCD. (This is the best we can do, given that $$$R=b(a+\frac{b-1}{2})$$$ and we can force $$$b$$$ to be prime.)

          Together with the idea from @above, it suffices to check divisors $$$\frac{R}{k}$$$ for $$$k$$$ up to $$$\frac{R}{\max(b^2/4, a+\frac{b-1}{2})} \approx \min(4a/b, b)$$$. Because $$$R \approx (4a/b)(b^2)$$$ this minimum is at most $$$R^{\frac{1}{3}}$$$.

          Checking if a divisor $$$\frac{R}{k}$$$ works can also be optimized to $$$O(k)$$$: enumerating the $$$k$$$ multiples of $$$\frac{R}{k}$$$ less than $$$R$$$, it suffices to calculate the largest $$$x$$$ such that $$$a + (a+1) + \cdots + (a+x) = \frac{x(x+1)}{2} + (x+1)a \leq C$$$ with quadratic formula, and check if $$$C \leq (a+b-x-1) + \cdots + (a+b-1)$$$. Each multiple can be done in $$$O(1)$$$.

          Combining both of these optimizations, the complexity is essentially $$$O(\text{sum of factors of R below }R^{\frac{1}{3}})$$$. Admittedly I don't have an asymptotic bound for this, but empirical data using highly composite numbers suggests it should be at most $$$R^{\frac{1}{2}}$$$ for reasonable $$$R$$$.

          Then fixing $$$a$$$ and varying $$$b$$$, the upper bound is maximized when $$$b \approx \sqrt{a} \implies R \approx a^{3/2}$$$, which gives the bound $$$a^{3/4}$$$, plus finding the largest divisor at most $$$\frac{b^2}{4}$$$ if required.

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

Auto comment: topic has been updated by skye_ (previous revision, new revision, compare).