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
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.
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
Easy way of explaination . It helped me . Thank you
Thank you i have tried many lecture or videos but cleared this concept sieve of eratosthenes here
@CodingBlocksIndia
4 жыл бұрын
Greet shivam! Good to hear that. Stay Subscribed to our channel & share the word with your friends for more awesome stuff.
Excellent explanation sir😍😍
This is a really great video thank you.
Can you please upload lectures on other cp algorithm
Bhai please btaado ye kis playlist me he apki channel ke
Hi can u please explain logic of problem 535B codeforces question
Best Explanation
at 18:20 second loop has an increment of j+i It will go out of bonds of the array
@sriram8027
4 жыл бұрын
kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found better explanation with clear complexity proof
Thanks brother ❤️❤️❤️❤️👍
thanks a lot brother
18:10, (on line 34) if j = i* i and j
@shreyasingh1258
4 жыл бұрын
Yes I also feel that 'i' should traverse from 3 to i*i
Thanks a ton. (y)
coding blocks♥️😍
Can you explain range between 5 to 10
champ!!!
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
4 жыл бұрын
You should use long instead of int as i*i might overflow
how is log(10^18)=60??
Time complexity is fine....wt about Space complexity..??
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
4 жыл бұрын
kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found better explanation with clear complexity proof
what is ll?
@CodingBlocksIndia
4 жыл бұрын
Long long
why you used size of array as 1000005
I have written the same code in code blocks.But it is not showing any output?
@abhishekvishwakarma7389
4 жыл бұрын
are you printing the output?
@abhijeetkumar2204
4 жыл бұрын
@@abhishekvishwakarma7389 yess bro
@abhijeetkumar2204
4 жыл бұрын
@@abhishekvishwakarma7389 if you have can can you share your code link
@abhishekvishwakarma7389
4 жыл бұрын
I think my code is correct but it shows run time error. I already commented my code.
@abhijeetkumar2204
4 жыл бұрын
@@abhishekvishwakarma7389 in case of large number your code will give tle if you are using int datatype.
n==2 condition is not required for the same reason as for not including of n==3 condition. Nice video
you have written the brute force approach wrong. that must be:- for(int i=2;i*i
Have anyone tried SPOJ Prime Generator? It's giving TLE even using Prime sieve!
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............
Bhai kya tha ye..🙄 😂
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
didnt help.
@sriram8027
4 жыл бұрын
kzread.info/dash/bejne/aXetpMhmqL2sZMY.html found a better explanation with complexity analysis