Solve These Questions for Good BIT Manipulation Intuition | CP Course | EP 65

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 72

  • @devacc9958
    @devacc9958 9 місяців тому +4

    In the second question it can be observed that in all the combinations of A and B to maximise the product (filling 1's for 0 in C), the sum of A and B is constant for given C. Using calculus it can be shown that if sum of two numbers is constant then the product will become larger as the numbers A and B will be close to each other and the product will be maximum when A = B = C / 2. So bits in A and B should be filled in such a way that the difference between A and B is minimum. This can be done by setting all the bits in A in which corresponding bit of C is set except MSB (last bit) and only setting that MSB of B in that case.

    • @SaurabhChaudhary600
      @SaurabhChaudhary600 9 місяців тому +1

      I had same intution but didn't have the proof, thanks!!

  • @almamunsiddiki7697
    @almamunsiddiki7697 5 місяців тому +1

    For the second question:
    1. find the number (lim) greater than C with all bits set.
    2.
    a) iterate through lim to 1, Let each number as A;
    b) in each iteration find B . wich is equal to A^C.
    c) find maximum product.
    Code for clear understanding:
    #include
    using namespace std;
    int main(){
    int c, a, b;
    long long ans = 1;
    cin >> c;
    int bits = 0, n;
    n = c;
    while(n > 0){
    bits++;
    n >>= 1;
    }
    int lim = pow(2, bits) - 1;
    for(int i = lim; i > 0; --i){
    b = c ^ i;
    ans = max(ans , b * 1LL * i);
    }
    cout

  • @gourishanker9975
    @gourishanker9975 3 роки тому +10

    Luv bhai awesome video..
    I have an another approach for 2nd question. Please check if it is correct
    Instead of generating all the subsets , what we can do is find A and B such that they are as close as possible to each other because we want to maximize the product..
    As said above , we we want to choose A and B as close as possible
    So , lets take A as bigger number and B be the smaller number .
    Let say ith is position of MSB in C ,
    So we set the ith bit in A
    And for rest of the set bits in C , we set the bits in B
    And if the bit is unset in C , we set the bit in both A and B
    Lets take an example of 13 ::
    Binary of 13 :- 1101
    A :. 1010
    B : 0111

    • @harshal0073
      @harshal0073 Рік тому

      yes, bro even i thought of the same approach, it is absolutely correct and less with less time complexity

    • @showrovmiah1035
      @showrovmiah1035 8 місяців тому

      I also thought that

  • @arkojitsanyal3219
    @arkojitsanyal3219 3 роки тому +4

    2nd question >> if A^B=C ==> A=C^B..... you just need to brute force for all values of B that are in range 1 to (1

  • @pushpajitbiswas3752
    @pushpajitbiswas3752 3 роки тому +6

    We can also solve the 2nd problem in O(1) time complexity
    let say we have our C = 13
    all we have to find the power of 2 which is just less than C, in this case it is 8
    so A = 8-1 = 7 (always)
    Now we need B which is also very simple, just do B = A ^ C.
    Now you have your A and B which is the largest possible pair, now just multiply them :)

    • @abhaypratap9898
      @abhaypratap9898 3 роки тому +1

      Cool 🙃

    • @souravkumar5120
      @souravkumar5120 2 роки тому

      but how you reached to this approach ,just hit and trial or some logic.

    • @pushpajitbiswas3752
      @pushpajitbiswas3752 2 роки тому

      @@souravkumar5120 By doing dry run and observation brother

    • @harsh6318
      @harsh6318 2 роки тому +1

      Yes i did the same

    • @vampzzz
      @vampzzz 2 роки тому

      @@pushpajitbiswas3752 It's a little late to reply but how did you come up with this that A =( pow of 2 just less than C) - 1 would always give us the highest multiple Could you elaborate a bit?

  • @divyampatni3571
    @divyampatni3571 11 місяців тому

    in second question we can further optimize the code. We can just iterate the set_bits.size() loop(the inner loop) from j=0 to j= (set_bits.size()/2 )+1 as after half of the loop has ended the values starting reversing in A and B. I kept an extra iteration for the odd case.

  • @AsifHussain-gl4ci
    @AsifHussain-gl4ci 11 місяців тому

    I am very thankfull of you for teaching in such a simple way.
    This us the best channel for those who want to do cp.
    Luv bhaiya will make the hard concepts simple.
    Thanks ones again.

  • @algotalk5368
    @algotalk5368 3 роки тому +2

    Luv good work u need millions subscribers

  • @sicklips
    @sicklips Рік тому +1

    Easy brute force for second problem :
    void solve() {
    int c; cin >> c;
    long long prod = 0;

    for(int i = 1; i

  • @saurabhkumarsingh9550
    @saurabhkumarsingh9550 3 роки тому

    👌🏻👌🏻👌🏻 great videos h only videos ko frequency km h apke kam ki vajah se.... Is chij ka regret rhta h

  • @divanshujain9449
    @divanshujain9449 3 роки тому +1

    Sir in the second ques, we just have to set the first bit of A . Then if xor is 1 we ALWAYS set the bit of B and will set bits of both A and B if xor of that bit is 0 .This will always give the correct output in the best optimised way.

  • @pritishpattnaik4674
    @pritishpattnaik4674 2 роки тому

    Bahut hi mast explanation

  • @amad1eus271
    @amad1eus271 3 роки тому +8

    I am following these lectures in compititive programming in my jee holidays ( it's so amazing ).
    I am just searching for some basic path for compititive programming and through this series (a noob like me who doesn't know anything and can't follow anything) I really benefited a lot.
    I am not preparing for jee adv as I already going to get CSE branch in my desired college XD

  • @harry-ns3wh
    @harry-ns3wh 2 роки тому

    App plz nesting of containers or examples ke sath karao or complex containers STL ke ander apne bhot basic nesting krayi thi like multiset inside there is a set and in set something is there then after comma same as that like multiset university this one isme input kese hongee element or agr ho bhi gye to output kese kre

  • @harshitsingh4764
    @harshitsingh4764 3 роки тому +1

    Ayo😲, Luv express is going at full speed.
    We are getting new videos (with great content) every 3-4 days.👌🏻

  • @sahilharad9222
    @sahilharad9222 3 роки тому +16

    Fun fact : He wears same T-shirt in all videos 😛

    • @iamluv
      @iamluv  3 роки тому +28

      why waste time in deciding to what to wear xD

    • @sahilharad9222
      @sahilharad9222 3 роки тому

      @@iamluv Good job brother 👍

    • @amad1eus271
      @amad1eus271 3 роки тому

      But don't you think that's pretty cool XD

    • @vinflyer2889
      @vinflyer2889 3 роки тому +2

      Like Mark Zuckerberg 😏

    • @sachinupreti7159
      @sachinupreti7159 3 роки тому

      @@iamluv Itna bhi time waste nahi hota bhai isme at most 1-2 min .

  • @ratneshpal6026
    @ratneshpal6026 3 роки тому +1

    East or West
    Luv is best.

  • @dhruvmalik8052
    @dhruvmalik8052 11 місяців тому

    Very helpful content

  • @aayush5474
    @aayush5474 3 роки тому +1

    bro make one video on segmented sieve

  • @harry-ns3wh
    @harry-ns3wh 2 роки тому

    in que of monk we have to find minimum amount demanded by monk to god of money so what we can do here let the price of bicycle is P and initially he demand for 1 rupees from god next day amount will be double then double again and again by his father we want exactly how much money he demand from god so that he reach to his goal so what we will do here after each double we will check whether the doubled amount is less the cost price we again double this cycle continues upto when the amount is greater or equal to P if amount is greater at iteration "n" then take "n-1" iteration and subtract in from P so that particular amount and plus one rupees he demand from god if P is equal to any iteration then the amount is 1 demanded from god

  • @akshatawasthi5277
    @akshatawasthi5277 6 місяців тому

    in second question,
    a simple solution would be like
    since we know if a^b=c, then c^b=a, so through this we can solve by running loop from 1 to n-1, and calculating the maximum as
    for(int i=1;i

    • @manoor0858
      @manoor0858 Місяць тому

      wowwww thats so easy im so dumbbb

  • @AmanKumarSinhaOfficial
    @AmanKumarSinhaOfficial 3 роки тому

    Please Upload a video daily...

  • @ankur_6174
    @ankur_6174 3 роки тому

    Bhaya, aapne koi dsa sheet follow ki thi kya ? Aapne khud ki dsa sheet banane ki sochi hai ?

  • @prafullashukla9823
    @prafullashukla9823 2 роки тому

    Sir,i am not able to understand the last part of code

  • @jhashivam28
    @jhashivam28 3 роки тому

    Bhaiya me Java mn yh follow krskta hu na.... CP playlist

  • @chiraggoyal9646
    @chiraggoyal9646 3 роки тому

    Thanks bhaiya

  • @saurabhm1102
    @saurabhm1102 3 роки тому

    bhaiya..combinatorics is missing in number theory.

  • @funenjoynilaypatel4553
    @funenjoynilaypatel4553 2 роки тому

    31 march 2022. 9:00 am

  • @wolfrikz7238
    @wolfrikz7238 3 роки тому

    You're amazing

  • @shridharsarraf2188
    @shridharsarraf2188 3 роки тому

    Luv bhai❤

  • @aashitAgrawal
    @aashitAgrawal Рік тому

    Here is my optimized solution
    #include
    using namespace std;
    int main()
    {
    long long n;
    cin >> n;
    long long a = 0, b = 0;
    long long count = 0;
    long long temp = n;
    while (temp != 0)
    {
    temp /= 2;
    count++;
    }

    // cout

  • @samagrapathak3854
    @samagrapathak3854 3 роки тому

    Bhaia aap to bolre the ki aab graph aaega

  • @Sonalisingh3
    @Sonalisingh3 3 роки тому +2

    Have you done all your exams of placements in C++ itself??
    I want to know that is C++ is enough for off campus placements coding as well as interview or there should be any other programming languages also??

    • @iamluv
      @iamluv  3 роки тому +6

      c++ is more than enough, for object oriented i personally prefer java

    • @Sonalisingh3
      @Sonalisingh3 3 роки тому

      @@iamluv thank you for reply...but I want to know that only C++ is enough for job also or one more language should be there

    • @iamluv
      @iamluv  3 роки тому +1

      @@Sonalisingh3 there is no generic answer to this, for placement c++ is enough, for working companies no language is enough, each company works with different stack, most of the people learn when they join in the process

    • @sahilharad9222
      @sahilharad9222 3 роки тому

      @@iamluv but I think java is easy for me can I continue with java

    • @AmanKumarSinhaOfficial
      @AmanKumarSinhaOfficial 3 роки тому

      @@iamluv Please upload one video daily...

  • @tiger7858
    @tiger7858 11 місяців тому

    4:02 "god se" 😅 nathuram godse

  • @mashapoguajay3322
    @mashapoguajay3322 3 роки тому

    U r from iiita

  • @অবহেলাজীবন-য৪ব

    Hello mujhe free fire hack auto headshot confi file do na please 1 file de do na

  • @p38_amankuldeep75
    @p38_amankuldeep75 2 роки тому

    ❤💙❤

  • @e.m.hasanprince4609
    @e.m.hasanprince4609 3 роки тому

    First comment

  • @grandparick3176
    @grandparick3176 3 роки тому

    Who is more talented Luv or kunal kushwaha?

    • @randomshorts2820
      @randomshorts2820 3 роки тому +2

      Luv

    • @manikantasai6118
      @manikantasai6118 3 роки тому +2

      Who is kunal?

    • @rishabh507
      @rishabh507 3 роки тому +7

      Bhai idhar padhne aaya hai ki comparison krne ?

    • @shridharsarraf2188
      @shridharsarraf2188 3 роки тому

      Anyday luv bhai. Wo kunal egoist ko luv bhai se mat compare kar😏

    • @grandparick3176
      @grandparick3176 3 роки тому +1

      @@shridharsarraf2188 a tune Sahi kaha bhai. Kunal larka talented ha but ego jeda ha.