u just saved my life on this test. Helping me work out this problem, u get a like comment and subscribe for that. Just ur explanation of prime factors was enough
If you're looking to remove duplicate prime factors you have a few approaches. You can conditionally append factors to the list of prime factors i.e. check if the number is already in the list and only if it's not, add it to the list. You could also return the list as a set by calling set(name_of_list) and that will remove all duplicates. There are more ways to do it but these are 2 simple methods.
Kaif, nice video, thanks for sharing! a couple of minor points: you can use /= instead of x = x/divisor, also why not initialize divisors with 2 and 3 and add 2 each time to the devisor so that the code run a bit faster (still O(n))? Thank you again for the video!
Hi Hamid, these are great suggestions, I will keep the shorthand syntax in mind for my next video and the suggestion of adding 2 after the divisor has reached 3 is a great little optimization. Thanks so much :)
Wouldn’t incrementing the divisor by 2 each time skip some factors?? Since on the first iteration, divisor is 2, incrementing by 2 would skip 3, no?? I need clarification..
Thank you for this. I try to explain new concepts every video, which is why the solution may not be optimal. Do you think you can share a better solution as a reply to this message? Cheers!
Hey! The idea is that if a number is not divisible by 2 then it won't be divisible by all multiples of 2 i.e. (4,6,8 etc), the same applies for all other numbers. Therefore, although we are iterating through all numbers in the divisor, we can be sure the next factor will always be a prime number. Hope this explains it 😁.
I have a doubt Initially we assigned divisor as 2. And when we implement by 1, it should be 3. Then how we get 5 and 7 in result???? Plz solve my doubt
So the idea is that if a number is not divisible by 2 then it won't be divisible by 4,6,8,10 i.e. multiples of two. This means that even though we are incrementing by 1 we can be sure that we will only be finding prime numbers such as 2,3,5,7 etc. Please do note that this probably isn't the most optimal way to solve the problem.
Seems like you haven't called the function, from what I can see your function is called "prime_fact" and I assume your print statement looks like this "print(prime_fact)". To print the result of the function you have to call it like this "print(prime_fact(argument))" where "argument" are the parameters/arguments that the function requires.
The point of that is once you've found a factor you need to divide the original number by the factor to get the next otherwise your loop would never end and you'll keep getting the same prime factor.
@@kaifk Could u help me with following:- def multiplication_table(num, i): """ this function returns the multiplication table of a number """ for i in range (1, 11): if num >= 0: product = num*i return product num = int(input("Enter positive no.")) print("{0} * {1} = {2}". format(num, i, multiplication_table(num, i))) error: name 'i' is not defined
The divisor is not incremented to the next prime factor "technically" but the divisor is only added to the list of prime factors only if it is a prime factor.
Have you tried it? It would be fun to see what happens (how long does the number have to be till your CPU can't handle it) I'd imagine higher than 11 since you're dividing by at least 2 each iteration 🤷
This is the best video I found on this problem, super well made video! Applause!
you are making great content for sure. hardwork and quality is evident. will share your channel with my friends! thank you!
Thanks a lot! Best explanation!
Thanks brother for this videos it helps me alot while, I was stuck in this prime factorization question.
Thank you very much! Such great explanations. I cant wait to get another of your tutorials. Thanks again.
Great explanation! what IDE are you using?
Just working on VSCode :)
superb and simple explanation...
Thank you!
Thank you so much
love your video dude!!!
Thank you
Great work, Thanks a lot brother. Really appriciate it.
u just saved my life on this test. Helping me work out this problem, u get a like comment and subscribe for that. Just ur explanation of prime factors was enough
smartly written code!
Thank you so much for this code ❤
I want to ask how will you remove the duplicate prime factors? Like what code needed to remove the duplicate prime factors?
If you're looking to remove duplicate prime factors you have a few approaches. You can conditionally append factors to the list of prime factors i.e. check if the number is already in the list and only if it's not, add it to the list. You could also return the list as a set by calling set(name_of_list) and that will remove all duplicates. There are more ways to do it but these are 2 simple methods.
Thanks for explaining how to do that so clearly
Thank you so much 😇😇😇
Thank you very much for this video.
The pleasure's mine 😊
Your sound is good. I think you need some foam sound board on the walls around your desk. It's make your audio sharper. Nice video.
Thanks for the advice I'll try that out for my next video :)
Kaif, nice video, thanks for sharing! a couple of minor points: you can use /= instead of x = x/divisor, also why not initialize divisors with 2 and 3 and add 2 each time to the devisor so that the code run a bit faster (still O(n))? Thank you again for the video!
Hi Hamid, these are great suggestions, I will keep the shorthand syntax in mind for my next video and the suggestion of adding 2 after the divisor has reached 3 is a great little optimization. Thanks so much :)
@@kaifk Your content is great, please keep them coming!
Wouldn’t incrementing the divisor by 2 each time skip some factors??
Since on the first iteration, divisor is 2, incrementing by 2 would skip 3, no??
I need clarification..
Very very useful
Thank you so much ❤️
You need to make more video like this 🙏
Next video should drop today! :)
Great work brother ❤️
Can you tell me what is the complexity of this algorithm
I believe the time complexity in Big O notation is O(n).
M guy you're a genius 🤩
you are great
for large input it will give tle
Thank you for this. I try to explain new concepts every video, which is why the solution may not be optimal. Do you think you can share a better solution as a reply to this message? Cheers!
Hi... Thank u for this video.... I have a doubt... How the divisor is exactly a prime number
Hey! The idea is that if a number is not divisible by 2 then it won't be divisible by all multiples of 2 i.e. (4,6,8 etc), the same applies for all other numbers. Therefore, although we are iterating through all numbers in the divisor, we can be sure the next factor will always be a prime number. Hope this explains it 😁.
well done
I have a doubt
Initially we assigned divisor as 2. And when we implement by 1, it should be 3. Then how we get 5 and 7 in result????
Plz solve my doubt
So the idea is that if a number is not divisible by 2 then it won't be divisible by 4,6,8,10 i.e. multiples of two. This means that even though we are incrementing by 1 we can be sure that we will only be finding prime numbers such as 2,3,5,7 etc. Please do note that this probably isn't the most optimal way to solve the problem.
@@kaifk ok sir understood.
Thanq for ur patience
I'm glad I could help :)
I'm getting output as
Can you paste the output as shown in your terminal here, that will allow me to better help.
Sir I am getting output like this
Where should I made mistakes $ir??
Seems like you haven't called the function, from what I can see your function is called "prime_fact" and I assume your print statement looks like this "print(prime_fact)". To print the result of the function you have to call it like this "print(prime_fact(argument))" where "argument" are the parameters/arguments that the function requires.
@@kaifk s sir I did it
Can I send my code?
@@kaifk
def prime_fact(a):
prime_factors=[]
divisor=2
while divisor
@@gayathri-8-i6s Yes please, that will help.
@@kaifk but it's not working sir
My brain just got 10 times bigger
Can’t wait to see more of this series 🤩
Thank youuuuuu
what's the point of x=x/divisor
def prime_factor(n):
"""
this function returns the prime factors of a number
"""
prime_factors = []
divisor = 2
while divisor
The point of that is once you've found a factor you need to divide the original number by the factor to get the next otherwise your loop would never end and you'll keep getting the same prime factor.
Your return statement is wrong, you want to return `prime_factors` not `prime_factor(n)`
@@kaifk yes i realized it right after i read ur comment and went through the code. Thanks.
@@kaifk
Could u help me with following:-
def multiplication_table(num, i):
"""
this function returns the multiplication table of a number
"""
for i in range (1, 11):
if num >= 0:
product = num*i
return product
num = int(input("Enter positive no."))
print("{0} * {1} = {2}". format(num, i, multiplication_table(num, i)))
error: name 'i' is not defined
good work
Thank you! Cheers!
The divisor is not incremented to the next prime factor that's wrong
The divisor is not incremented to the next prime factor "technically" but the divisor is only added to the list of prime factors only if it is a prime factor.
@@kaifk yes you are right, i know this while typing the comment, but i just need a person to reply me... thanks
very well and clearly explained set of processes!
Thank you so much!
Yuor code is too small to see in Mobile screen. Next time zoom in or make the font size bigger.
Thank you for the feedback, I'll take it on board for the next video :)
💯💯💯🔥🔥🔥
yeah but try doing this with an eleven digit number without frying your cpu
Have you tried it? It would be fun to see what happens (how long does the number have to be till your CPU can't handle it) I'd imagine higher than 11 since you're dividing by at least 2 each iteration 🤷