HOW TO FIND PRIME FACTORS? | Project Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ธ.ค. 2024

ความคิดเห็น • 78

  • @Oubayy
    @Oubayy หลายเดือนก่อน

    This is the best video I found on this problem, super well made video! Applause!

  • @satyadeepapatra414
    @satyadeepapatra414 2 ปีที่แล้ว +1

    you are making great content for sure. hardwork and quality is evident. will share your channel with my friends! thank you!

  • @poprostukamil123
    @poprostukamil123 27 วันที่ผ่านมา

    Thanks a lot! Best explanation!

  • @praddyotahayaran9847
    @praddyotahayaran9847 3 ปีที่แล้ว +1

    Thanks brother for this videos it helps me alot while, I was stuck in this prime factorization question.

  • @kizzavincent
    @kizzavincent 3 ปีที่แล้ว +1

    Thank you very much! Such great explanations. I cant wait to get another of your tutorials. Thanks again.

  • @davidbachy5627
    @davidbachy5627 ปีที่แล้ว

    Great explanation! what IDE are you using?

    • @kaifk
      @kaifk  ปีที่แล้ว

      Just working on VSCode :)

  • @deepakreddy9112
    @deepakreddy9112 2 ปีที่แล้ว

    superb and simple explanation...

  • @NikhilKumar-qq3vc
    @NikhilKumar-qq3vc ปีที่แล้ว

    Thank you!

  • @davidajimati980
    @davidajimati980 ปีที่แล้ว

    Thank you so much

  • @fauzan3823
    @fauzan3823 3 ปีที่แล้ว +1

    love your video dude!!!

    • @kaifk
      @kaifk  3 ปีที่แล้ว

      Thank you

  • @MrhmmD
    @MrhmmD 2 ปีที่แล้ว

    Great work, Thanks a lot brother. Really appriciate it.

  • @chrismessmer3265
    @chrismessmer3265 2 ปีที่แล้ว

    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

  • @uttkarsh7823
    @uttkarsh7823 3 ปีที่แล้ว

    smartly written code!

  • @musicalnotes9862
    @musicalnotes9862 ปีที่แล้ว

    Thank you so much for this code ❤

  • @vittorialuna-h7h
    @vittorialuna-h7h 2 ปีที่แล้ว +1

    I want to ask how will you remove the duplicate prime factors? Like what code needed to remove the duplicate prime factors?

    • @kaifk
      @kaifk  2 ปีที่แล้ว +1

      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.

  • @jdubb5394
    @jdubb5394 3 ปีที่แล้ว

    Thanks for explaining how to do that so clearly

  • @neilrathod6681
    @neilrathod6681 3 ปีที่แล้ว

    Thank you so much 😇😇😇

  • @amandeepkaur1361
    @amandeepkaur1361 4 ปีที่แล้ว +1

    Thank you very much for this video.

    • @kaifk
      @kaifk  4 ปีที่แล้ว

      The pleasure's mine 😊

  • @kitefrog
    @kitefrog 2 ปีที่แล้ว

    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.

    • @kaifk
      @kaifk  2 ปีที่แล้ว

      Thanks for the advice I'll try that out for my next video :)

  • @hsoley
    @hsoley 2 ปีที่แล้ว

    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!

    • @kaifk
      @kaifk  2 ปีที่แล้ว +2

      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 :)

    • @hsoley
      @hsoley 2 ปีที่แล้ว +1

      @@kaifk Your content is great, please keep them coming!

    • @irishwinter
      @irishwinter 2 ปีที่แล้ว

      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..

  • @III__VasanthS
    @III__VasanthS 4 ปีที่แล้ว +2

    Very very useful

    • @kaifk
      @kaifk  4 ปีที่แล้ว

      Thank you so much ❤️

  • @vinaynaik953
    @vinaynaik953 4 ปีที่แล้ว +2

    You need to make more video like this 🙏

    • @kaifk
      @kaifk  4 ปีที่แล้ว +1

      Next video should drop today! :)

  • @harshsingh12678
    @harshsingh12678 3 ปีที่แล้ว

    Great work brother ❤️

  • @rohitbarhate9597
    @rohitbarhate9597 2 ปีที่แล้ว

    Can you tell me what is the complexity of this algorithm

    • @kaifk
      @kaifk  2 ปีที่แล้ว

      I believe the time complexity in Big O notation is O(n).

  • @wasimbardai3012
    @wasimbardai3012 4 ปีที่แล้ว

    M guy you're a genius 🤩

  • @deeproy8136
    @deeproy8136 ปีที่แล้ว

    you are great

  • @kalyanking1080
    @kalyanking1080 3 ปีที่แล้ว

    for large input it will give tle

    • @kaifk
      @kaifk  3 ปีที่แล้ว +1

      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!

  • @karthikashankar2766
    @karthikashankar2766 4 ปีที่แล้ว

    Hi... Thank u for this video.... I have a doubt... How the divisor is exactly a prime number

    • @kaifk
      @kaifk  4 ปีที่แล้ว +3

      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 😁.

  • @jayashanfernando835
    @jayashanfernando835 3 ปีที่แล้ว

    well done

  • @gayathri-8-i6s
    @gayathri-8-i6s 3 ปีที่แล้ว

    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

    • @kaifk
      @kaifk  3 ปีที่แล้ว +2

      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.

    • @gayathri-8-i6s
      @gayathri-8-i6s 3 ปีที่แล้ว +1

      @@kaifk ok sir understood.
      Thanq for ur patience

    • @kaifk
      @kaifk  3 ปีที่แล้ว +1

      I'm glad I could help :)

    • @gayathri-8-i6s
      @gayathri-8-i6s 3 ปีที่แล้ว

      I'm getting output as

    • @kaifk
      @kaifk  3 ปีที่แล้ว

      Can you paste the output as shown in your terminal here, that will allow me to better help.

  • @gayathri-8-i6s
    @gayathri-8-i6s 3 ปีที่แล้ว

    Sir I am getting output like this
    Where should I made mistakes $ir??

    • @kaifk
      @kaifk  3 ปีที่แล้ว

      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.

    • @gayathri-8-i6s
      @gayathri-8-i6s 3 ปีที่แล้ว

      @@kaifk s sir I did it
      Can I send my code?

    • @gayathri-8-i6s
      @gayathri-8-i6s 3 ปีที่แล้ว

      @@kaifk
      def prime_fact(a):
      prime_factors=[]
      divisor=2
      while divisor

    • @kaifk
      @kaifk  3 ปีที่แล้ว

      @@gayathri-8-i6s Yes please, that will help.

    • @gayathri-8-i6s
      @gayathri-8-i6s 3 ปีที่แล้ว

      @@kaifk but it's not working sir

  • @pc-qn7mu
    @pc-qn7mu 4 ปีที่แล้ว +1

    My brain just got 10 times bigger

    • @pc-qn7mu
      @pc-qn7mu 4 ปีที่แล้ว +1

      Can’t wait to see more of this series 🤩

    • @kaifk
      @kaifk  4 ปีที่แล้ว +2

      Thank youuuuuu

  • @hemantsikarwar1918
    @hemantsikarwar1918 2 ปีที่แล้ว

    what's the point of x=x/divisor

    • @hemantsikarwar1918
      @hemantsikarwar1918 2 ปีที่แล้ว

      def prime_factor(n):
      """
      this function returns the prime factors of a number
      """
      prime_factors = []
      divisor = 2
      while divisor

    • @kaifk
      @kaifk  2 ปีที่แล้ว +2

      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
      @kaifk  2 ปีที่แล้ว +2

      Your return statement is wrong, you want to return `prime_factors` not `prime_factor(n)`

    • @hemantsikarwar1918
      @hemantsikarwar1918 2 ปีที่แล้ว

      @@kaifk yes i realized it right after i read ur comment and went through the code. Thanks.

    • @hemantsikarwar1918
      @hemantsikarwar1918 2 ปีที่แล้ว

      @@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

  • @gouravnaruka4840
    @gouravnaruka4840 3 ปีที่แล้ว

    good work

    • @kaifk
      @kaifk  3 ปีที่แล้ว

      Thank you! Cheers!

  • @ventacode
    @ventacode 2 ปีที่แล้ว

    The divisor is not incremented to the next prime factor that's wrong

    • @kaifk
      @kaifk  ปีที่แล้ว

      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.

    • @ventacode
      @ventacode ปีที่แล้ว +1

      @@kaifk yes you are right, i know this while typing the comment, but i just need a person to reply me... thanks

  • @MaxP-tl7rz
    @MaxP-tl7rz 4 ปีที่แล้ว

    very well and clearly explained set of processes!

    • @kaifk
      @kaifk  4 ปีที่แล้ว

      Thank you so much!

  • @arifulamin4914
    @arifulamin4914 2 ปีที่แล้ว

    Yuor code is too small to see in Mobile screen. Next time zoom in or make the font size bigger.

    • @kaifk
      @kaifk  2 ปีที่แล้ว

      Thank you for the feedback, I'll take it on board for the next video :)

  • @wasimbardai3012
    @wasimbardai3012 4 ปีที่แล้ว

    💯💯💯🔥🔥🔥

  • @tiltltt
    @tiltltt 3 ปีที่แล้ว +1

    yeah but try doing this with an eleven digit number without frying your cpu

    • @kaifk
      @kaifk  2 ปีที่แล้ว

      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 🤷