Sieve of Eratosthenes:: Topics That You Should Know With Sieve
Sieve of Eratosthenes:: Topics That You Should Know With Sieve
1. Modular exponentiation
2. Greatest Common Divisor (GCD)
3. Extended Euclidean algorithm
4. Modular multiplicative inverse
Tutorial:
https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/tutorial/
Problems:
1. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/calculate-the-power/
2. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/name-count/
3. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/beautiful-primes/description/
4. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/diedie/
Once you are done with all these topics,you can move on to the next topic.
Sieve of eratosthenes:
While solving problems related to number theory we all come across situation where we
need to find prime numbers from L to R,number of divisors of given number,factors of given
number etc.All of these problem could be solved using one efficient algorithm called seive.It has
many variants.
Tutorial:
https://www.geeksforgeeks.org/sieve-of-eratosthenes/
https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/tutorial/
Once you are done with tutorials,you should know how to these things efficiently.
1. Prime numbers in given range L to R. (1<=L<=R<= 106 )
2. Count number of divisors of given number
3. Prime factorization of given number in O(logn)
Problem: Find all prime numbers between L to R. ( 1<=L<=R<= 1012 ) ( R-L<= 106 )
We will find all numbers between 1 to 106 . We will store them in array say primes.Now we will
iterate through all members of primes and multiples of p[i] between given range(L to R) will
be marked as non-prime.Unmarked numbers between L to R will be our prime numbers.
Problems on sieve:
Since these problems are very time sensitive… Use FAST i/o to avoid TLE.
Easy
1. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/can-you-guess/
2. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/hell-1/
3. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/archery-1/
4. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/practi
ce-problems/algorithm/sum-of-primes-7/
5. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/practi
ce-problems/algorithm/ashu-and-prime-factors-4/
Medium:
1. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/gotta-beat-em-all/
2. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/practi
ce-problems/algorithm/nearest-prime-a828361b/
3. https://www.hackerearth.com/ja/practice/math/number-theory/basic-number-theory-2/pra
ctice-problems/algorithm/holi-and-division-function-1dfc3294/
Hard:
1. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-1/practi
ce-problems/algorithm/kala-set/
2. https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/practi
ce-problems/algorithm/mike-and-gcd-issues/
Answer:
1. Suppose prime number x is between 10^6 to 10^12. Then multiples of this prime number till 10^12 will
contain at least one prime which is in range 1 to 10^6.hence primes till 10^6 will be enough.
This can be also proved using fact that if two prime numbers greater than 10^6 say x1,x2 construct a
number y,then y will definitely exceed range of 10^12.
If you want to learn about prime factorization or want to do some easy math questions check
this doc ,
https://docs.google.com/document/d/1fI2xLi8afbcv4w525DeCZW4Y0hw5gK8AIRdYK0itdf4/edit
?usp=sharing