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
@devacc99589 ай бұрын
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.
@SaurabhChaudhary6009 ай бұрын
I had same intution but didn't have the proof, thanks!!
@gourishanker99753 жыл бұрын
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 Жыл бұрын
yes, bro even i thought of the same approach, it is absolutely correct and less with less time complexity
@showrovmiah10358 ай бұрын
I also thought that
@arkojitsanyal32193 жыл бұрын
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
@darshanpagar18942 жыл бұрын
iterations will be same
@pushpajitbiswas37523 жыл бұрын
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 :)
@abhaypratap98982 жыл бұрын
Cool 🙃
@souravkumar51202 жыл бұрын
but how you reached to this approach ,just hit and trial or some logic.
@pushpajitbiswas37522 жыл бұрын
@@souravkumar5120 By doing dry run and observation brother
@harsh63182 жыл бұрын
Yes i did the same
@vampzzz2 жыл бұрын
@@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?
@divyampatni357111 ай бұрын
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-gl4ci10 ай бұрын
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.
@algotalk53683 жыл бұрын
Luv good work u need millions subscribers
@sicklips Жыл бұрын
Easy brute force for second problem : void solve() { int c; cin >> c; long long prod = 0; for(int i = 1; i
@saurabhkumarsingh95503 жыл бұрын
👌🏻👌🏻👌🏻 great videos h only videos ko frequency km h apke kam ki vajah se.... Is chij ka regret rhta h
@pritishpattnaik46742 жыл бұрын
Bahut hi mast explanation
@dhruvmalik805211 ай бұрын
Very helpful content
@sahilharad92223 жыл бұрын
Fun fact : He wears same T-shirt in all videos 😛
@iamluv3 жыл бұрын
why waste time in deciding to what to wear xD
@sahilharad92223 жыл бұрын
@@iamluv Good job brother 👍
@amad1eus2713 жыл бұрын
But don't you think that's pretty cool XD
@vinflyer28893 жыл бұрын
Like Mark Zuckerberg 😏
@sachinupreti71593 жыл бұрын
@@iamluv Itna bhi time waste nahi hota bhai isme at most 1-2 min .
@harry-ns3wh2 жыл бұрын
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
@harshitsingh47643 жыл бұрын
Ayo😲, Luv express is going at full speed. We are getting new videos (with great content) every 3-4 days.👌🏻
@amad1eus2713 жыл бұрын
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
@ratneshpal60263 жыл бұрын
East or West Luv is best.
@divanshujain94492 жыл бұрын
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.
@chiraggoyal96462 жыл бұрын
Thanks bhaiya
@aayush54743 жыл бұрын
bro make one video on segmented sieve
@funenjoynilaypatel45532 жыл бұрын
31 march 2022. 9:00 am
@shridharsarraf21883 жыл бұрын
Luv bhai❤
@harry-ns3wh2 жыл бұрын
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
@AmanKumarSinhaOfficial3 жыл бұрын
Please Upload a video daily...
@wolfrikz72383 жыл бұрын
You're amazing
@prafullashukla98232 жыл бұрын
Sir,i am not able to understand the last part of code
@ankur_61743 жыл бұрын
Bhaya, aapne koi dsa sheet follow ki thi kya ? Aapne khud ki dsa sheet banane ki sochi hai ?
@jhashivam283 жыл бұрын
Bhaiya me Java mn yh follow krskta hu na.... CP playlist
@saurabhm11023 жыл бұрын
bhaiya..combinatorics is missing in number theory.
@akshatawasthi52776 ай бұрын
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Ай бұрын
wowwww thats so easy im so dumbbb
@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
@samagrapathak38543 жыл бұрын
Bhaia aap to bolre the ki aab graph aaega
@Sonalisingh33 жыл бұрын
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??
@iamluv3 жыл бұрын
c++ is more than enough, for object oriented i personally prefer java
@Sonalisingh33 жыл бұрын
@@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
@iamluv3 жыл бұрын
@@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
@sahilharad92223 жыл бұрын
@@iamluv but I think java is easy for me can I continue with java
@AmanKumarSinhaOfficial3 жыл бұрын
@@iamluv Please upload one video daily...
@অবহেলাজীবন-য৪ব3 жыл бұрын
Hello mujhe free fire hack auto headshot confi file do na please 1 file de do na
@mashapoguajay33223 жыл бұрын
U r from iiita
@p38_amankuldeep752 жыл бұрын
❤💙❤
@tiger785811 ай бұрын
4:02 "god se" 😅 nathuram godse
@e.m.hasanprince46093 жыл бұрын
First comment
@grandparick31763 жыл бұрын
Who is more talented Luv or kunal kushwaha?
@randomshorts28203 жыл бұрын
Luv
@manikantasai61183 жыл бұрын
Who is kunal?
@rishabh5073 жыл бұрын
Bhai idhar padhne aaya hai ki comparison krne ?
@shridharsarraf21883 жыл бұрын
Anyday luv bhai. Wo kunal egoist ko luv bhai se mat compare kar😏
@grandparick31763 жыл бұрын
@@shridharsarraf2188 a tune Sahi kaha bhai. Kunal larka talented ha but ego jeda ha.