YouKn0wWho's blog

By YouKn0wWho, 5 weeks ago, In English

Thanks for participating in the contest blobheart. We hope you liked the problems. We would love to hear your feedback in the comments.

If you find anything wrong in the editorial which is more likely to happen because we have written a rather long editorial to make you understand the solutions better, then comment below.

We also tried to write the thought process of how you can come up with the solution for the easier problems. The approach I followed is similar to what the current AI agents do. They first generate some thoughts, then do some actions, then gather observations, and repeat the process until they find the solution. Hope you will like this approach.

Also, don't forget to upvote the editorial. See you in the next contest!

Also, please rate the problems after checking the editorial. Because otherwise you might have solved it in a very cumbersome way that you will end up hating the problem.


How did you find the contest?
Which problem is your most favourite?
Which problem you hate the most?

Also, huge props to redpanda for creating awesome manim video editorials for problems A to D. Check it out here: https://www.youtube.com/watch?v=elRvvUbk1J4

2039A - Shohag Loves Mod

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039B - Shohag Loves Strings

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039C1 - Shohag Loves XOR (Easy Version)

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039C2 - Shohag Loves XOR (Hard Version)

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039D - Shohag Loves GCD

Author: YouKn0wWho

Tutorial
Code (Solution 1)
Code (Solution 2)
Rate the Problem

2039E - Shohag Loves Inversions

Author: YouKn0wWho

Tutorial
Code
Code (by wyrqwq, without initial casework)
Rate the Problem

2039F1 - Shohag Loves Counting (Easy Version)

Author: YouKn0wWho

Tutorial
Code (by LipArcanjo)
Rate the Problem

2039F2 - Shohag Loves Counting (Hard Version)

Author: YouKn0wWho

Tutorial
Code (unoptimized)
Code (optimized)
Rate the Problem

2039G - Shohag Loves Pebae

Author: YouKn0wWho

Tutorial
Code
Rate the Problem

2039H1 - Cool Swap Walk (Easy Version)

Author: wuhudsm

Tutorial
Code
Rate the Problem

2039H2 - Cool Swap Walk (Hard Version)

Author: wuhudsm

Tutorial
Code
Rate the Problem
  • Vote: I like it
  • -167
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Even after solving A,B my rating went from 999 to 994 why?

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Many people solved C1 and higher difficulty problems, so your rank dropped to 6000+ out of ~9100+ which gets calculated as a slightly lower performance than your last rating.

    You can check more on rating calculation at https://codeforces.net/blog/entry/20762 or try out some CodeForces Rating Predictor for a better view on the rank vs rating.

»
5 weeks ago, # |
  Vote: I like it +12 Vote: I do not like it

Bitmask + XOR = Pain

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Shohag Loves Bitmasks :')

»
5 weeks ago, # |
  Vote: I like it +93 Vote: I do not like it

Shohag loves OEIS (specially A079752)

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

LonggVuz bitmasks almost killed me, the problem D saved my rating ._.

»
5 weeks ago, # |
Rev. 3   Vote: I like it +88 Vote: I do not like it

F2: Cool problem, but why set the time limit so tight? The model solution (and most of the contestants' solutions) run in over 3s, and I couldn't get my solution to run much faster than 5s during the contest. :(

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +38 Vote: I do not like it

    I agree. It's a cool problem but the time limit is too tight

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

I liked B, C1, C2, E. Thanks for the round. H also looks interesting

»
5 weeks ago, # |
  Vote: I like it +22 Vote: I do not like it

Anyone else solved C2 using binary search ? 😂 😂

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What's the approximate rating of D?

»
5 weeks ago, # |
  Vote: I like it +61 Vote: I do not like it

The problem E does not request even ability to think. We need only slow solution that can calculate the number of possible arrays without modulo for $$$n < 14$$$ (which is easy to implement) and Wolfram Mathematica function FindSequenceFunction, which attempts to find a simple function that yields the sequence, when given successive integer arguments. Using the slow solution, we get the following sequence $$$(0, 1, 2, 5, 19, 102, 682, 5321, 47071, 464570, 5057058, 60166913, 776595027)$$$ of the answers. Now, we can use FindSequenceFunction to obtain the solution:

FindSequenceFunction[{0, 1, 2, 5, 19, 102, 682, 5321, 47071, 464570, 
  5057058, 60166913, 776595027}]

It gives the answer:

DifferenceRoot[Function[{y, n}, 
    {1 + (2 + n)*y[n] + (-3 - n)*y[1 + n] + 
          y[2 + n] == 0, y[1] == 0, y[2] == 1, y[3] == 2}]]

It is the recurrence relation, which can be simply coded: 292998575.

»
5 weeks ago, # |
Rev. 2   Vote: I like it +107 Vote: I do not like it

Some learnings as an Author: Judging by the votes and comments it seems like people mostly liked the problems individually but didn't like that most problems were mathy and didn't have enough variations. So I will try to keep that in mind and will add more variations to the contest in the future.

And I am also not happy that during the contest we found out that some people found the second difference/derivative of the sequence on OEIS. I searched on OEIS before but couldn't find it (I saw that it's not there but I didn't notice that there are some deltas matching for another sequence that were written on the OEIS page, I guess I have to be better regarding finding sequences on OEIS). Otherwise, we would have definitely modified the problem. Sorry for this issue.

Hopefully next time I will try to bring a more diverse round. Thanks for participating in the round!

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Why Shohag loves so much number theory, although problems are really good.

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Bro how does D have more solves than C2

»
5 weeks ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

Hello every one I have been trying to learn more about mobius function and it’s application but I couldn’t find any resources Can some one help me in this matter ?

»
5 weeks ago, # |
  Vote: I like it +40 Vote: I do not like it

The time limit of F2 is very bad. The solution which runs in $$$\sum_i \sigma^2(i)$$$ should have passed easily. It should not be a close call. The optimisations into $$$\sum_i \sigma(i) \times p(i)$$$ do not add any new ideas, and the constraints suggest there is a solution faster than this.

The inclusion of both C1 and C2 may make sense in terms of round balance (which frankly, is still pretty bad), but I don't see it being a good idea to test the same skill-set twice.

»
5 weeks ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it

There's a cute solution to D.

Let cnt(x) be the number of divisors of x, not including 1 and x.

Then, set answer[i] to be equal to S[m - cnt(i)].

That's it :)

And if the index is ever equal to zero or negative (assuming indexing starts at 1), then output -1.

The reasoning stems from the same thoughts as the editorial, though I am too tired to write out a formal proof.

»
5 weeks ago, # |
Rev. 3   Vote: I like it +19 Vote: I do not like it

My solution of how managed to solve C2 but also at the same time failed miserably at it. I am able to skip an observation, but with paid a serious price in terms of implementation.

We need to check for $$$x| x \ xor \ y$$$ or $$$y | x\ xor\ y$$$. The second case is only possible if $$$y <= 2x$$$. We focus on the first case, rewrite $$$x xor y$$$ as $$$x + y - 2 (x\ and\ y)$$$. Let $$$k$$$ be the smallest integer such that $$$2^k > x$$$. Then, the value of $$$y\ mod\ 2^k$$$ is enough to determine $$$x\ and\ y$$$. For each $$$0 \leq c < 2^k$$$, we consider $$$y = a2^k + c$$$, this becomes a certain divisbility condition imposed on $$$a$$$, which can be solved with a certain CRT. This solution is now $$$O(x \log x)$$$.

To optimise, It can be seen (by looking at the implementation), that the required extended modular inverse to calculate is same for every $$$c$$$, so the $$$log x$$$ time to calculate inverse is common. This gives a solution of $$$O(x)$$$.

Being able to come up with a highly technical alternative solution, but unable to actually follow through with it in implementation, turns out to costed me greatly in this round. Submission: 292984478.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The condition $$$x|x \oplus y$$$ is equivalent to $$$x|y-2(x&y)$$$. Since $$$y=a2^k+c$$$, we just need to determine whether there exists some $$$a$$$ st $$$x|a2^k+c-2(x&c)$$$, or equivalently whether there exists some $$$a$$$ st $$$a2^k \equiv 2(x&c)-c \pmod x$$$. Could you please explain how you do this? I tried to understand from your code, but it has always been hard for me to read other's code, plus I don't know Kotlin. Any help would be greatly appreciated, thank you.

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      you will be seeking some $$$a$$$ such that it is within some calculated range (depending on $$$m$$$), and $$$a2^k \equiv d$$$, where $$$d = 2(c\ and\ x) -x$$$, and thus fixed per $$$c$$$. It is not too difficult to solve that the possible $$$a$$$ must be something of the form $$$As+B$$$ for some integer $$$A$$$,$$$B$$$, which can be calculated with (extended) modular inverses. The formula is as follows:

      fun equateSolution(a:Int, b:Int, m:Int):Pair<Int,Int>?{
          // smallest positive integer k s.t. ka == b (mod m)
          //Return: (smallest positive integer, common differenc between solution)
          val g = gcd(a,m)
          if(b % g != 0) return null
          return ((extendedInverse(a/g, m/g)!! * (b/g).toLong()) % m).toInt() to (m/g)
      }
      
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I might have a little less mathy and simpler explanation for C2.

Let’s say x XOR y is a multiple of x.

So,
x XOR y = c * x (where c is any integer >= 0).

  1. If c = 0:
    x XOR y = 0 implies x = y (which is a valid case).

  2. If c = 1:
    x XOR y = x implies y = 0 (which is an invalid case since y > 0).

  3. If c = 2:
    x XOR y = 2 * x implies y = (2 * x) XOR x.

In this case, y > x, because the leftmost bit in 2 * x is not set in x. Therefore, the XOR operation introduces a set bit that makes y > x.

Thus, x XOR y is a multiple of x if and only if y > x.


Now, consider y = (c * x) XOR x for some constant c.

  • From this, we can deduce:
    y <= c * x + x and y >= c * x - x.

  • So, for any multiple of x, the value of y can differ from c * x by at most x.

To solve this:

  1. Choose all multiples of x that are <= m.
  2. For the last multiple, check to the left and right of it to ensure the corresponding range of y is valid within m.

Personally, I used binary search to find the largest y such that y = (c * x) XOR x <= m. Then, I checked the next two multiples of x beyond this point to see if their corresponding range of y also falls within m.


Dividing the Range of y

Since 1 <= y <= m, we can split the range of y into two parts:

  1. For 1 <= y <= x:
    Here, we can simply loop over all values of x in O(n) and check if x XOR y is divisible by x or y.

  2. For x < y <= m:
    From the earlier reasoning, x XOR y is divisible by x. But not divisible by y, as shown in the editorial in Case 2.

This approach ensures correctness and efficiency with a O(n) solution.

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Thanks.I think in this way but can't find out y <= c*x; also x is efficient as there is m = 1e18

    Please tell me why k+2 to (k+10)??

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      If you play with xor a little and see how xor works (think about most significant bit), then u'll see that for any two numbers x and y (where y > x), we have

      y-x <= x xor y <= x+y

      So, if you replace y with cx, then you have that inequality mentioned above.

      At the time of the contest I was not sure about this elaborate proof and perfectly with the constraints. I just figured out that there would be some multiples of x above m, so I just thought there could not be more than 10 multiples. So I just took a guess and went with it. Later on I found out that there could be at most 2 such multiples.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Thanks Please check my submission (http://codeforces.net/contest/2039/submission/292965221)I was solve C1 within 1 to x and got ac but tutorial say 2*x is there any edge case for my solution?

        • »
          »
          »
          »
          »
          5 weeks ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Yeah I also, just solved looping till x. Maybe there is either no test case for that or if we see it more rigorously, we can prove it.

          • »
            »
            »
            »
            »
            »
            5 weeks ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Actually I got an observation that after the msb of x if bit is on in y then x^y is not a divisor of y or x, it's only possibly when all bit is off in x but x = 0 is not possible so always answer lie in x. Just share my thinking it can be right or wrong.

            • »
              »
              »
              »
              »
              »
              »
              4 weeks ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              Hey,can you please tell me why did you put (y <= m) in the condition,in your c1 solution?

»
5 weeks ago, # |
  Vote: I like it +8 Vote: I do not like it

xor is like subtraction without borrowing.(problem c2 editorial correction)YouKn0wWho

»
5 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

C2: I found a "cool" way to solve it using some insight in the pattern of valid y when y>x. In particular the pattern has length 2^k, where k is 32 - clz(x) - ctz(x). In this way we can then easily count by blocks of the given length and then iterate through the pattern untill there are enough numbers. This solution works in O(n), my submission took more time because I used larger upperlimits to be sure of choosing the right pattern and avoid silly mistakes.

Submission: 292969986

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Did I think wrong or there exist a clerical error in the F1 question? If sequence a is a non decreasing sequence, then the maximum value of subinterval with length $$$k$$$ should be the last $$$n - k+1$$$ numbers instead of $$$k$$$ numbers?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

why my code gets tle any help is appreciated problem d. 293022163

»
5 weeks ago, # |
  Vote: I like it -15 Vote: I do not like it

Well Explained.

»
5 weeks ago, # |
  Vote: I like it -14 Vote: I do not like it

Shit E.Don't make this kind of problem again.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

What is OEIS?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I am not very good at math but this contest is full of math. This sucks.

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Thank you YouKn0wWho for such good editorials. I would love to see more such editorials.

Edit: I don't know why did the comment get so many dislikes, sorry if my comment looks irrelevant. I just wanted to appreciate the editorial as I got to learn something new from it.

»
5 weeks ago, # |
  Vote: I like it -48 Vote: I do not like it

B was too easy, for a Div 1+2 Contest ! (Not to mention Shohag's obession w/ maths.)

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

So, under these circumstances, wouldn't it be possible to have a time limit in C1?

Since 1≤t≤1e4 and 1≤x≤1e6.

»
5 weeks ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

I'd like to make C2 case 1 clearer:

Initial conditions:

  • $$$ 1\le y \le m $$$
  • $$$ p = x \oplus y \rightarrow y = x \oplus p $$$
  • $$$ p | x $$$
  • We need to find values of p such that $$$ 1 \le p \oplus x \le m $$$

Let's consider ranges $$$ [1;m-x]$$$, $$$(m-x;m+x]$$$ and $$$(m+x;\infty)$$$

  • All values of p in the first range $$$ p \le m-x $$$ all valid, because then we say $$$ p + x \le m $$$ and by property $$$ p \oplus x \le p + x $$$, so $$$ p \oplus x \le p + x \le m $$$. Thus, for this range, we add $$$ \lfloor\frac{m-x}{x}\rfloor $$$ to our answer.
  • For second range we can check manually if $$$p$$$ values in that range are divisible by $$$x$$$ and if $$$p\oplus x \le m$$$, and add those values to our answer.
  • For the last range, we know by property that $$$ p - x \le p \oplus x $$$, and as we are in the third range $$$ p-x > m $$$, so $$$ m < p - x \le p \oplus x $$$. As in this range $$$ m < p \oplus x $$$, we don't add anything to our answer.
  • »
    »
    5 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    The first point, "... Thus, for this segment, we add $$$\lfloor \frac{m - x}{x} \rfloor$$$ to our answer.".

    I can't understand this last argument. What is the proof?

    Edit: Gotcha! We need to get the number of multiples of $$$x$$$ in the range $$$[1, m - x]$$$ so $$$p$$$ can be any of these multiples and there is always a valid $$$y$$$ for such $$$p$$$.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thank you for your explaination,which helps me a lot QWQ

»
5 weeks ago, # |
  Vote: I like it +13 Vote: I do not like it

when x=2 y=4 lcm(x,y) = 4 but 2*max(x,y) = 8 it against the Solution in c2 how to solve it

»
5 weeks ago, # |
  Vote: I like it +13 Vote: I do not like it

The C2's case3 is wrong, x = 2 and y = 4 then boom lcm(x,y)≥2⋅max(x,y) is wrong

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

For C2, the editorial for case 3 says when x isn’t equal to y, lcm(x,y) >= 2*max(x,y) isn’t this not true for x=2, y=4 for example? How does this prove that only x=y works for this case?

  • »
    »
    5 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    An alternative proof would be something like:

    Wlog let y > x. lcm(x,y) >= y. Assume (x ^ y)/lcm(x,y)=k (where k is some integer).

    k!=1, (x^y)/lcm(x,y) <= (x+y)/y < 2. So k = 0 which would mean x=y.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    no, the interpretation they tried to show may be is the following: given: x^y < 2*max(x,y) and we want lcm(x,y) divide x^y . now, try with all multiple of lcm(x,y) which are less than 2*max(x,y) because x^y always smaller than 2*max(x,y) and if we take lcm(x,y) = max(x,y) then then first multiple of lcm(x,y) will be lcm(x,y) it self and we made it equal to x^y => x^y = max(x,y) => one of them must be zero if x!=y, which is a contradiction. so lcm(x,y) must be at least 2*max(x,y). may be they wanted this, not sure.

»
5 weeks ago, # |
Rev. 4   Vote: I like it +19 Vote: I do not like it

Is there a lower bound on the minimum number of operations needed for problem H? My randomized code can pass every test currently using no more than $$$n+3$$$ operations, but cannot squeeze the number to $$$n+2$$$ on test 25.

UPD: This code used at most $$$n-1$$$ operations and passed. Of course we have to use at least $$$1$$$ operation when $$$n=2$$$, so it seems that this code reached the lower bound?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I don't feel like there is any reason why the theoretical lower limit of O(log n) cannot be reached. When solving the problem, I saw that for small n, 3 operations could get every permutation (n<=7). It seems that the operation is extremly versatile, but as usual such versatility is hard to made use of constructively.

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

.

»
5 weeks ago, # |
  Vote: I like it +36 Vote: I do not like it

Well, what's wrong with C2? imo it is indeed a nice problem (maybe nicer without C1). But currently it got 165 downvotes.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem C1, I got ac but In my implementation where 1 to x is sufficient to find out Y. Please check my submission and tell me is there any edge case can i got wa??Also in tutorial y <= 2 * x but i can do it in x https://codeforces.net/contest/2039/submission/292965221

»
5 weeks ago, # |
  Vote: I like it +24 Vote: I do not like it

Shohag really loves GCD.

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

i feel shame for not solving D

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

please help me where is it better to solve archive tasks

acmp or timus?

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

i will remember this round like one of the most funniest in my life. B problem is so good, love math and patterns. and c1 is really most funniest shit i ever done. it's shame i didn't done a D problem(TL at one of the last tests)

my point is-why people downvoting this round???? it was really cool round

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

D , solution 2 i understand that this solution achieve optimal sequence but i can't prove why when im at some index that have m or more divisors and these divisors use all m values so the answer -1 !

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    at index i, u need to find the biggest number in S where a[i] ≠ a[divisors of i], so when there is no a possible number, the answer is -1.

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      i mean why it's -1 if there's no possible number depending on my divisors values ,one could say my previous steps were bad that what i need to prove

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Because the optimal way is also to choose the max possible number,
        to make sure that a[divisors of i] ≠ gcd(a[divisors of i], a[i]), is to make sure that the values of a[divisors of i] is greater than a[i], then the values of gcd(a[divisors of i],a[i]) will never be equal to a[divisors of i].
        so the answer is -1 when there is no enough numbers.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain what's going on with their solution to E? In their last paragraph ("And to count..."), their last sum goes from 1+2+3+..,+(m-2) to (m-1)(m-2)/2-1 which has an extra -1 term.

Also, I thought that there would be j places to put the 1 instead of j-1. You can put the extra 1 before the 1 and before any of the previous j-1 zero terms for a total of j instead of j-1 spots.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Never mind, I figured it out. There's just a small typo. Instead of the sum starting at j = 2, it should start at j = 3.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Here is an explanation for the formula in G (no explanation was given), for anyone who wants it:

Denote S_g as the number of assignments of a's such that the a's have gcd divisible by g. Denote "a_u can not be a multiple of any prime number p <= h_u" by (*)

First, the formula of S_g only makes sense when considering g's that are good, because otherwise, for a vertex of index x that is on the longest path (so h_x = D), there will be a prime p less than D that divides a_x (since g divides a_x and there is a prime p less than D that divides g, so p divides a_x), so the condition (*) is broken.

The mobius function in there is used for Inclusion-exclusion principle purposes. To see that, let's consider all the primes between 1 and m, denote them by p_1,...p_r. Denote by B_i the set of assignments that have their gcd not divisible by p_i. Then what we desire is the size of the set Intersection(B_i, for i from 1 to r). From the inclusion-exclusion principle: |Inters(all B_i)| = |Union(all B_i)| — sum of all |B_i| + sum of all |B_i inters B_j| — ...

|Union(all B_i)| = S_1, and |for k many B_i's : Inters of B_i's| = S_(product of those k indexes), with its sign being the parity of k. Note that we don't need numbers that contain a prime twice in their factorization, so the mobius function is ideal for our use since it excludes them.

The answer thus is sum from 1 to m of whether_g_is_good(g) * mobius(g) * S_g.

How to compute S_g: Since g divides all a_i, and g is coprime with all numbers between 1 and D since it is good, we thus get that any number p <= h_i that doesn't divide a_i also doesn't divide a_i / g. There are floor(m/g) numbers divisible by g in the interval [1, m]. Hence, for each vertex with index i, we have f_(floor(m/g)),(h_i) ways to choose an a_i that is divisible by g and isn't divisible by anything less than h_i. Therefore, S_g = product for all i in [1, n] of f_(floor(m/g)),(h_i)

»
5 weeks ago, # |
  Vote: I like it +31 Vote: I do not like it

Have u proved in problem F that all valid sequences can be generated from a valid non-decreasing sequence?

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Maximum is on one of the ends of the array. Suppose we remove it. Then all gcd-s still need to be increasing, so the property that maximum is on one of the edges still holds. Suppose our original maximum was on the right. Then we can reverse the array. So when we remove maximum, we always remove the first element. If we wouldn't erase maximums, just reverse the suffix if the first element of that suffix is less than its last. Nothing changed and our array is non-increasing

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

what's wrong with this solution for C2 submission link

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

problems were really nice and these long explainations were really nice too

but why sohag is loving niumber theory so much

»
4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

You wrote good editorial for beginners. It is great to see that you are showing how to think on the problems.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

The solution to problem C2 is really confusing.

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I have an another thought of that.

    Let $$$x' = 2^k$$$, and $$$\frac{x'}{2} \le x < x'$$$.

    For that $$$y \le x'$$$, we could find that the only valid $$$y$$$ satisfy $$$(x \oplus y) \mid y$$$, or $$$x \oplus y$$$ should be over $$$y$$$. So we can bruteforce in $$$[1, x']$$$.

    Let $$$n' = 2^t$$$, and $$$n' \le n < 2n'$$$.

    Then we can find that, which $$$p$$$ of $$$px \le n'(p \ge 1)$$$, $$$y = px \oplus x$$$ could be satisfy $$$y \le n$$$. So we can easily calculate it by $$$\left\lfloor\frac{x'}{x'}\right\rfloor / x - 1$$$.

    And for that over $$$n'$$$, bruteforce again.

    You can read my code to summary that.

    293451693

»
4 weeks ago, # |
  Vote: I like it -24 Vote: I do not like it

还是我太菜了

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

in problem A instead of bugging in maths deeply just try to think easily that what should be value of a1 that modulus with 1 comes 0 what should be the value of a2 that modulus with 2 comes 1 ,what should the value of a3 that modulus with 3 produce 2- you will get your ans sequence of odd numbers starting from 1 to 99 will be our ans i.e 2*i+1 upto n.thanks open to discussion

»
2 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Can Someone tell why this solution of Problem-D is giving wrong answer.

For each index i I am checking the idx stored in the factors.

Spoiler
»
2 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I appreciate that you have defined the meaning of gcd of two numbers and a lexicographically larger array in the D problem. But you have not defined what agcd(i,j) means.