We can further simplify this by starting the loop from min(m, n) /2 to 1 and seperate sentence for testing the min(m, n) . Eg: if we take 100 and want to know the factors, first 100 is a factor, then there is no factor from 99 to 51. So we can skip that part completely. This is true for every other numbers.
@tavilefty2 жыл бұрын
exactly man. this comment needs to be pinned.
@girish8579 Жыл бұрын
What about odd numbers?
@mrtalksick6178Ай бұрын
@@girish8579 instead of dividing by 2, take the quotient of the division i.e. min(m, n)//2.
@abhishek-wt5xm4 жыл бұрын
i dont know why people are getting difficulties in understanding but i would must say i there cant be an easier explanation. really a great resource for understanding the algorithm syntax and know the best solution you also explained the way to decrease the time and ans space complexity of the algorithm thankyou
@coldcoke9254 Жыл бұрын
probably because it s the first lecture and we are already using concepts of functions and loops and lists...I'd recommend watching a one shot lecture on python by codewithharry and then coming to this that's what I did and now all this seems really simple...don't even need to watch all of it only till chapter 8.
@ruturajjadhav89054 жыл бұрын
def gcd(num1,num2): return max(list(set([i for i in range(1,num1+1) if num1 % i == 0]).intersection(set([i for i in range(1,num1+1) if num1 % i == 0])))) ## intersection : combines the common factors of given two sets ##just two lines
@SlickShitt3 жыл бұрын
after intersection you used the first parameter instead of num2
@adityamehra72382 жыл бұрын
My brain literally exploded after realising there was 1 another way to write code for this gcd...... Meanwhile professor : you said 1? Wait hold my mike...... 💥💥... A beautiful lecture
@BiswajitDas-lk7pp2 жыл бұрын
Amazing 😀😀😀
@mandarchincholkar72505 жыл бұрын
Marvelous logic... Amazing... 👏👏👏👏🎉🎉🎊🎊🎊 only experienced programmers will get it..🔥🔥🔥
@panthrohit5 жыл бұрын
Not an experienced programmer, still I get it... :)
@mandarchincholkar72505 жыл бұрын
@@panthrohit then you nailed it hardly.. 😎😎😎😎
@panthrohit5 жыл бұрын
@@mandarchincholkar7250 This reminds me of the saying 'working hard or working hardly'. Whats my takeaway here....🤔😛😬
probably because it s the first lecture and we are already using concepts of functions and loops and lists...I'd recommend watching a one shot lecture on python by codewithharry and then coming to this that's what I did and now all this seems really simple...don't even need to watch all of it only till chapter 8.
@anshulojha56994 жыл бұрын
The algo that u explain if I will learn that methods to minimize the all codes with time and memory then I will be the rank 1 in Google contests 🙏🙏
@sameers85103 жыл бұрын
You are simply superb sir Awesome explanation
@bhargavdobariya58593 жыл бұрын
great explanation....thanks a lot sir
@izharkhankhattak2 жыл бұрын
nice
@vatsal_gamit3 жыл бұрын
def gcd3(m,n): return max([i for i in range(1,min(m,n)+1) if ((m%i)==0 and (n%i)==0)]) print(gcd3(3575,978))
@tavilefty2 жыл бұрын
wonderful lecture.
@arpita06086 жыл бұрын
The shorter python program was confusing min(m, n) this part
@vatsalgupta006 жыл бұрын
Divisor of a number cannot be larger than the number. Since we are trying to find common divisors, only divisors of smaller number are suffcient.
@DineshJunjariyaBEE4 жыл бұрын
min(m,n) gives least of the two numbers
@anshulojha56994 жыл бұрын
Like min(6,8) so dono me vo common no hoga vo 6 se thoe hamesha less hi hoga like 2 here . That's why they used this concept ✅
@mritunjay37233 жыл бұрын
A one line code -- print(next(a for a in range(63,0,-1) if 8888%a==0 and 63%a==0))
@sravanchilumula52135 жыл бұрын
classes are in not the correct order please correct it!
@pratapkhandekar83225 жыл бұрын
You are explaining code directly It is hard to understand
@sanjayguptacg4865 жыл бұрын
low sound.
@sagarsagar-xr7bo4 жыл бұрын
Low sound boring ,speak loudly sir
@prashnatdivase85234 жыл бұрын
def gcd(m,n): fm=[] # list down factor of m in fm fn=[] # list down factor of m in fn for i in range(1,m+1): if (m%i ==0): fm.append(i) print("fm is",fm) for j in range(1,n+1): if (n%j ==0): fn.append(j) print("fn is",fn) cf=[] # for returning largest value for k in fm: if k in fm: cf.append(k) print("The largest GCD is: %d "%cf[-1]) gcd(10,8) above programs give correct output but i would like to understand why below program is not giving same output: def gcd(m,n): i=min(m,n) while i>=0: if m%i==0 and n%i==0: return i else: i=i-1 v=gcd(10,8) print(v) Sorry if i am missing anything and would be great if someone explain last optimize example in details
@coldcoke9254 Жыл бұрын
the code works just fine tho, just chane
@venkatashasidharreddychali7485 Жыл бұрын
give the brackets correctly, it worked for me, I alos got the wrong output when i used this (m%i) ==0 & (n%i) ==0 after tweaking it to this ((m%i) ==0) & ((n%i) ==0), i got the correct output
@prashnatdivase8523 Жыл бұрын
@@venkatashasidharreddychali7485 thank you
@bhupiagra16 жыл бұрын
you said actually any common factor must be less than min(m, n) but how this statement is justifying gcd of (2, 4) ?
@tabassumhebbalkar6 жыл бұрын
including the minimum of both.
@panthrohit5 жыл бұрын
Must be less than or equal to min(m,n)
@DineshJunjariyaBEE4 жыл бұрын
he meant min or less than min
@exploringlife29044 жыл бұрын
not running in python mrcf
@gauravjoshi75893 жыл бұрын
i am not getting any error and also not getting any output
@sumitbhattacharyya20586 жыл бұрын
sound quality is not satisfactory
@pk156925 жыл бұрын
You can use a volume booster for chrome to enhance the sound volume