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