How to find Xor of all numbers from 1 to N and the number of set bits at any position?

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 9

  • @cfstepofficial
    @cfstepofficial  3 месяца назад +1

    Slides link.excalidraw.com/p/readonly/JL4H8fOkL3nXIzfK7Cgp?darkMode=true
    Practice Contest codeforces.com/group/7Dn3ObOpau/contest/539212

  • @sonugupta147
    @sonugupta147 3 месяца назад

    The quality of your content is just too good. I think I have become addicted to these videos and the beautiful concept behind these problems and the way you present them is just appreciable. If possible, plz make the dedicated lectures on these concepts like graph theory, dynamic programming, bits, constructive algorithms, math etc. It would really helps us a lot in our journey. As not only it will serve us as a training guide but also raise the bar of our understanding a particular concept. Thank you so much 🙏🏻🙏🏻🙏🏻

    • @cfstepofficial
      @cfstepofficial  3 месяца назад +1

      I am glad you liked the videos. Sure, I'll try to bring more variety of contents on this channel, but no commitments at the moment.

  • @ashrafuldowla6214
    @ashrafuldowla6214 3 месяца назад

    Excellent explanataion

  • @aryamanchandra537
    @aryamanchandra537 3 месяца назад +1

    Love your videos beautiful explanation as always

  • @frtt9555
    @frtt9555 3 месяца назад

    Very clear, keep it up bro great video

  • @mazenmohamed530
    @mazenmohamed530 3 месяца назад

    Thanks for you videos I love how your explanation.
    I have one question: why we chose blocks of length 4 ? why not 2 or 8 ? does it change how we look at the modulo answer ?

    • @cfstepofficial
      @cfstepofficial  3 месяца назад +2

      Good question. Remember that at the start of the video, I told you that bits repeat in groups of 2^i. Therefore, each $2^i$ would work, except 2. (Because if you pick block size of 2, the lowest bit set column will not have the xor of block equal to zero).
      However, if you pick 2^i which is higher than 2^2, you would have more if-else to handle (because there can be 2^i values of modulo). So, we just wanted to find the smallest 2^i that works, which is 2^2. In fact, it is pretty obvious now that if 2^2 works, 2^3 would also work (because 8 = 4 + 4, 16 = 4 + 4 + 4 + 4). But even if you didn't knew that 2^2 works, you at least knew that bits at 2^i have a repeating pattern.
      In fact, for the exercise at the end, you need to use the fact that bits repeat at 2^i, so you have to create different block size in each column. Column i from right would contain block size of 2^i. Then, computing set bits would be easy.

    • @mazenmohamed530
      @mazenmohamed530 3 месяца назад

      @@cfstepofficial Understood, thanks