Prime

  1.  Sieve of Eratosthenes –  Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number.  GFG
  2. Least prime factor of numbers till n – Given a number n, print least prime factors of all numbers from 1 to n.  GFG 
    Algo: Use  Sieve of Eratosthenes logic. 
  3. Print all prime factors of a given number.
    Algo:
    1. GFG  Divide the number n with n till it’s possible. Then start dividing the number from 3 till sqrt(n) and save/print numbers that divide the number completely.
    Complexity: sqrt(n)
    2. GFG Use Sieve of Eratosthenes logic.
    Complexity : O(log n)

    All the question can be solved based on the logic and almost similar code from  Sieve of Eratosthenes implementation. 
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s