Sieve of Eratosthenes | Fastest Way of Finding Prime Numbers in Competitive Coding

The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to a specified integer. The beauty of this algorithm lies in the simplicity of the concept that is used. It simply eliminates all the multiples of a number as those multiples can never be prime and print the ones that are not eliminated after the whole process. It is one of the most simple algorithms out there to find all the primes in a range.
---------------------- About Coding Blocks ---------------------------
Check courses on - online.codingblocks.com [Free Trial Available]
Coding Blocks India's best Programming and software training institute offers courses like C++ and Java, Data Structures and Algorithms, Web and Android Development(Java and Kotlin), Competitive Programming, Coding Interview Preparation and Machine Learning, AI and more. Registration open for Online and Offline Coding classes.Take advantage of the professionals who have worked with bigwigs like Sony, Cyanogen, Micromax.
#programming #coding #learning
Like our FaceBook Page - / codingblocksindia
Follow us on Instagram - / codingblocks
Follow us on Twitter - / codingblocksin
Source code available on - github.com/coding-blocks-arch...
LinkedIn Profile - / coding-blocks
For more interesting tutorials - / codingblocksindia

Пікірлер: 63

  • @CodingBlocksIndia
    @CodingBlocksIndia4 жыл бұрын

    Become a Master in Competitive Coding with CB's Master Course in Competitive Programming. Visit cb.lk/1VCUZ for more information on the course. Use Coupon Code "KZread" to avail 25% Off on Our Courses.

  • @AnkitSaiyan
    @AnkitSaiyan3 жыл бұрын

    at line 30, inside the for loop you can write i*i10 is never gonna be true if i =11 j = i*i j = 121 ....and 121

  • @vaishnaviboje
    @vaishnaviboje4 жыл бұрын

    Easy way of explaination . It helped me . Thank you

  • @shivamkumar-qp1jm
    @shivamkumar-qp1jm4 жыл бұрын

    Thank you i have tried many lecture or videos but cleared this concept sieve of eratosthenes here

  • @CodingBlocksIndia

    @CodingBlocksIndia

    4 жыл бұрын

    Greet shivam! Good to hear that. Stay Subscribed to our channel & share the word with your friends for more awesome stuff.

  • @AmitSingh-cs2hb
    @AmitSingh-cs2hb4 жыл бұрын

    Excellent explanation sir😍😍

  • @UTRG-UnderTheRain
    @UTRG-UnderTheRain Жыл бұрын

    This is a really great video thank you.

  • @satyamanisrivastava7818
    @satyamanisrivastava78184 жыл бұрын

    Can you please upload lectures on other cp algorithm

  • @harshitrajani8369
    @harshitrajani83694 жыл бұрын

    Bhai please btaado ye kis playlist me he apki channel ke

  • @pallavivarshney1744
    @pallavivarshney17444 жыл бұрын

    Hi can u please explain logic of problem 535B codeforces question

  • @likhitachinnari4773
    @likhitachinnari47733 жыл бұрын

    Best Explanation

  • @muhammadrumi6665
    @muhammadrumi66654 жыл бұрын

    at 18:20 second loop has an increment of j+i It will go out of bonds of the array

  • @sriram8027

    @sriram8027

    4 жыл бұрын

    kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found better explanation with clear complexity proof

  • @justcode......2254
    @justcode......2254 Жыл бұрын

    Thanks brother ❤️❤️❤️❤️👍

  • @surajtopal9940
    @surajtopal99403 жыл бұрын

    thanks a lot brother

  • @hritikagarwal7676
    @hritikagarwal76764 жыл бұрын

    18:10, (on line 34) if j = i* i and j

  • @shreyasingh1258

    @shreyasingh1258

    4 жыл бұрын

    Yes I also feel that 'i' should traverse from 3 to i*i

  • @kunalsinghgusain2070
    @kunalsinghgusain20704 жыл бұрын

    Thanks a ton. (y)

  • @natsuagarwaldragneel8388
    @natsuagarwaldragneel83884 жыл бұрын

    coding blocks♥️😍

  • @muthuji8053
    @muthuji80534 жыл бұрын

    Can you explain range between 5 to 10

  • @MadForCs16
    @MadForCs164 жыл бұрын

    champ!!!

  • @abhishekvishwakarma7389
    @abhishekvishwakarma73894 жыл бұрын

    for 2 test cases, this program is not working. it gives a run-time error for the first test case and the time limit is exceeded for the second test case. my code in java is: import java.util.*; public class Main { public static void main(String args[]) { Scanner s = new Scanner(System.in); int t=s.nextInt(); while(t-->0){ // for t test cases int l=s.nextInt(); // finding prime numbers in b/w l and r int r=s.nextInt(); int[] arr=new int[r+1]; for(int i=3;i

  • @Anand-wi4yb

    @Anand-wi4yb

    4 жыл бұрын

    You should use long instead of int as i*i might overflow

  • @vanshvyas4149
    @vanshvyas41493 жыл бұрын

    how is log(10^18)=60??

  • @nileshkethavath694
    @nileshkethavath6944 жыл бұрын

    Time complexity is fine....wt about Space complexity..??

  • @sadmanmehedisivan6581
    @sadmanmehedisivan65814 жыл бұрын

    why did you use i as an int in the first loop and long long i in the second the loop.?couldn't we use any one for both of them?And why did u use boolisprime function?we didn't use it in the main function..Otherwise got the idea u provided greatly

  • @sriram8027

    @sriram8027

    4 жыл бұрын

    kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found better explanation with clear complexity proof

  • @rachitsinghvi6592
    @rachitsinghvi65924 жыл бұрын

    what is ll?

  • @CodingBlocksIndia

    @CodingBlocksIndia

    4 жыл бұрын

    Long long

  • @ujjwalyadav9009
    @ujjwalyadav90093 жыл бұрын

    why you used size of array as 1000005

  • @abhijeetkumar2204
    @abhijeetkumar22044 жыл бұрын

    I have written the same code in code blocks.But it is not showing any output?

  • @abhishekvishwakarma7389

    @abhishekvishwakarma7389

    4 жыл бұрын

    are you printing the output?

  • @abhijeetkumar2204

    @abhijeetkumar2204

    4 жыл бұрын

    @@abhishekvishwakarma7389 yess bro

  • @abhijeetkumar2204

    @abhijeetkumar2204

    4 жыл бұрын

    @@abhishekvishwakarma7389 if you have can can you share your code link

  • @abhishekvishwakarma7389

    @abhishekvishwakarma7389

    4 жыл бұрын

    I think my code is correct but it shows run time error. I already commented my code.

  • @abhijeetkumar2204

    @abhijeetkumar2204

    4 жыл бұрын

    @@abhishekvishwakarma7389 in case of large number your code will give tle if you are using int datatype.

  • @UtkalSinha
    @UtkalSinha4 жыл бұрын

    n==2 condition is not required for the same reason as for not including of n==3 condition. Nice video

  • @supratimbhattacharjee5324
    @supratimbhattacharjee53244 жыл бұрын

    you have written the brute force approach wrong. that must be:- for(int i=2;i*i

  • @rishi3308
    @rishi33084 жыл бұрын

    Have anyone tried SPOJ Prime Generator? It's giving TLE even using Prime sieve!

  • @ananyaarya2465
    @ananyaarya24654 жыл бұрын

    The comment ( //if the current number is not marked (it is prime)) doesn't makes sense,i mean if its' not marked then it is even,and any even number except 2 can't be prime............

  • @prashantsandilya6197
    @prashantsandilya61973 жыл бұрын

    Bhai kya tha ye..🙄 😂

  • @anandsingh-mp4zv
    @anandsingh-mp4zv2 жыл бұрын

    Total useless, all optimization were useless, why don't you study linear sieve and then make some video. You can't say NLogNlogN is approx linear

  • @ishrarchowdhury4850
    @ishrarchowdhury48504 жыл бұрын

    didnt help.

  • @sriram8027

    @sriram8027

    4 жыл бұрын

    kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found a better explanation with complexity analysis