Sieve of Eratosthenes | Journey into cryptography | Computer Science | Khan Academy

Sieve of Eratosthenes allows us to generate a list of primes.
Watch the next lesson: www.khanacademy.org/computing...
Missed the previous lesson? www.khanacademy.org/computing...
Computer Science on Khan Academy: Learn select topics from computer science - algorithms (how we solve common problems in computer science and measure the efficiency of our solutions), cryptography (how we protect secret information), and information theory (how we encode and compress information).
About Khan Academy: Khan Academy is a nonprofit with a mission to provide a free, world-class education for anyone, anywhere. We believe learners of all ages should have unlimited access to free educational content they can master at their own pace. We use intelligent software, deep data analytics and intuitive user interfaces to help students and teachers around the world. Our resources cover preschool through early college education, including math, biology, chemistry, physics, economics, finance, history, grammar and more. We offer free personalized SAT test prep in partnership with the test developer, the College Board. Khan Academy has been translated into dozens of languages, and 100 million people use our platform worldwide every year. For more information, visit www.khanacademy.org, join us on Facebook or follow us on Twitter at @khanacademy. And remember, you can learn anything.
For free. For everyone. Forever. #YouCanLearnAnything
Subscribe to Khan Academy’s Computer Science channel: / channel
Subscribe to Khan Academy: kzread.info_...

Пікірлер: 49

  • @Dimension5Productions
    @Dimension5Productions3 жыл бұрын

    I just did this up to 100k. I started at the start of quarantine.

  • @learningandgamingwithsaach8413

    @learningandgamingwithsaach8413

    3 жыл бұрын

    Yeh

  • @christosbinos8467

    @christosbinos8467

    2 жыл бұрын

    I was surprised that I could use javascript to compute up to 10m almost instantly.

  • @Dimension5Productions

    @Dimension5Productions

    2 жыл бұрын

    @@christosbinos8467 Yeah I did up to a billion on python

  • @hil449

    @hil449

    2 жыл бұрын

    @@christosbinos8467 ofc, the standard sieve runs in O(n * log(log(n))), thats extremely fast, in c++ you'de be able to calculate up to 10^9 in one second

  • @ryanventurino3578
    @ryanventurino35784 жыл бұрын

    Wonderful. Clear explanation, I liked the brief background for context, and the description was helpful and the perfect level of detail. Thank you.

  • @DavidaThatch
    @DavidaThatch Жыл бұрын

    This was a perfect explanation, thank you!!

  • @Silberdragon1
    @Silberdragon1 Жыл бұрын

    Good Video. I forgot how it worked but you reminded me again. Thanks a lot!

  • @aadil4236
    @aadil4236 Жыл бұрын

    What a beautiful thing!!! If this is not enlightenment I don't know what is.

  • @Ali_Emran
    @Ali_Emran4 жыл бұрын

    WOW I UNDERSTAND EVERYTHING

  • @attilatoth1396
    @attilatoth13967 жыл бұрын

    Thanks!

  • @lycan2494
    @lycan24945 жыл бұрын

    great video..

  • @hansangjung6063
    @hansangjung60634 жыл бұрын

    Thank you.

  • @avoriginal9342
    @avoriginal9342Ай бұрын

    The pseudocode I’m failing to understand, so from 2 till sqrt of n if a is unmarked then a is prime, 2 will be unmarked, which makes it price, now for all multiples of 2, 4-6-8 etc are marked as composite, then 3 and starting from 9 to n, so at what point do we check for example 79 if we are only checking from 2 until sqrt(n), if we picked n=100 then we’d only check until 10, so what about all the number after 10 that are not marked as composite, and nowhere does it say we are checking them

  • @aelng1681
    @aelng1681 Жыл бұрын

    super cool

  • @moonman239
    @moonman2392 жыл бұрын

    I wonder about something. Would it be faster to check if n is prime if, instead of listing all the primes, we calculated the row and column on which the number would lie and then used that information to check if the number is prime? For example, 27 is on row 3 column 7 (or, row 2 column 6 if you're doing zero-based indexing) What if we tried using that information to decide if 27 is prime?

  • @yajaman

    @yajaman

    Жыл бұрын

    If the information about whether a prime is encoded in its row and column value, you would be able to solve the twin prime conjecture

  • @AbhishekVerma-zt7nu
    @AbhishekVerma-zt7nu3 жыл бұрын

    Why start at n^2 ?

  • @aydc6740

    @aydc6740

    Жыл бұрын

    you won’t find any primes under n (the point of the sieve) by starting at n^2.

  • @thelast2233
    @thelast22333 жыл бұрын

    what is the range of long in java

  • @peiceofcheese87

    @peiceofcheese87

    2 жыл бұрын

    From -2^63 to (2^63)-1

  • @thelast2233

    @thelast2233

    2 жыл бұрын

    @@peiceofcheese87 one more question that i really stuck right now also when I see problem there is constrian like 10 ^5 and I count with t if required I know big o and I know how o(n^2) work like two loops n times goes and more on it 1 st problem is 10 ^5 means this range 100000 but we have interger range 2^63 second is when I saw constarin I got idea that I need long for 10^16 but how can I know this time bruteforce works as begginer my code will very length and many time miss edge case and so on so what should i do? Do I need to see any video or how do I practice also is akrbra bazzi formula helps

  • @maxfromukraine1630
    @maxfromukraine16302 жыл бұрын

    What does he mean by "unmarked"?

  • @fovibhaassrivastava4951

    @fovibhaassrivastava4951

    7 ай бұрын

    In code, it would mean an array of booleans where all values are set to true. Each time we find a composite, we mark it by changing its value to false.

  • @ulti72
    @ulti725 жыл бұрын

    can you explain its complexity

  • @FilipeSilva1

    @FilipeSilva1

    2 жыл бұрын

    O(sqrt(n))

  • @fovibhaassrivastava4951

    @fovibhaassrivastava4951

    7 ай бұрын

    O(n log(log(n)))

  • @Wahee1
    @Wahee16 жыл бұрын

    0:10

  • @yafethtb
    @yafethtb2 жыл бұрын

    Sorry if this is a noob question. Why it must use square root of n? Why square root?

  • @file4318

    @file4318

    2 жыл бұрын

    Because factors come in pairs. Take for example 16. One pair would be 1, 16... another 2, 8... 4, 4... notice they intesect on the square root (4*4=16). This means a factor cannot be above the square without having a factor pair below it. And therefore if there is no factors below the square root there can be none above either

  • @the_m_original

    @the_m_original

    Жыл бұрын

    suppose n is the maximum number you use to get primes. (primes up to n, suppose its 100) and p is the unmarked number you are using to mark out multiples at p = 2, you use the square of that number (2^2 = 4) to get the starting point for multiples of p. then you repeat, as explained here, to look for unmarked numbers (p = 3, p^2 = 9, so start the multiples counter at number 9.) then, as ALSO explained here, once p reaches 11 and n is 100, the square of p will be larger than n, which we dont want, so we stop, right where p is nearby the square root of n or 100, which is 10.

  • @bharathiDevi001
    @bharathiDevi0014 жыл бұрын

    Here is the Program code: kzread.info/dash/bejne/paxnpdlqZLvAn8Y.html

  • @sarlarnsulonundedesi5913
    @sarlarnsulonundedesi59133 жыл бұрын

    hi from leetcode :D

  • @pablocarames3261
    @pablocarames32615 жыл бұрын

    Holaaaaaa

  • @michaelfortanely5715
    @michaelfortanely57154 жыл бұрын

    based

  • @Progamer-wt9ir

    @Progamer-wt9ir

    4 жыл бұрын

    Just see Dream yt

  • @waffles_1823
    @waffles_18233 жыл бұрын

    65 is composite

  • @0_-
    @0_-4 жыл бұрын

    I made a python program with this and can you tell me if this is the same? (Ask me for the code)

  • @cait1yn_
    @cait1yn_4 жыл бұрын

    Thanks i needed to cheat on my homework cause its 10 pm RN so yea THANK YA

  • @HiteshLadla

    @HiteshLadla

    4 жыл бұрын

    Why would you cheat

  • @Progamer-wt9ir

    @Progamer-wt9ir

    4 жыл бұрын

    Lol

  • @marieconpacuribot2718
    @marieconpacuribot27183 жыл бұрын

    Why is it a bit confusing

  • @raresaturn
    @raresaturn7 ай бұрын

    65 is not prime

  • @Mylok_
    @Mylok_5 жыл бұрын

    oaaaaaaaaaaaaaa

  • @Progamer-wt9ir
    @Progamer-wt9ir4 жыл бұрын

    Lol imagine top comment being with 5 likes

  • @darquenite
    @darquenite5 жыл бұрын

    Com-Paw-sit. Not compuhzit. So cringey.