Open In App

k-th prime factor of a given number

Last Updated : 28 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Given two numbers n and k, print k-th prime factor among all prime factors of n. For example, if the input number is 15 and k is 2, then output should be “5”. And if the k is 3, then output should be “-1” (there are less than k prime factors). 
Examples
 

Input : n = 225, k = 2        
Output : 3
Prime factors are 3 3 5 5. Second
prime factor is 3.

Input : n = 81, k = 5
Output : -1
Prime factors are 3 3 3 3

 

Recommended Practice

A Simple Solution is to first find prime factors of n. While finding prime factors, keep track of count. If count becomes k, we return current prime factor. 
 

C++




// Program to print kth prime factor
# include<bits/stdc++.h>
using namespace std;
 
// A function to generate prime factors of a
// given number n and return k-th prime factor
int kPrimeFactor(int n, int k)
{
    // Find the number of 2's that divide k
    while (n%2 == 0)
    {
        k--;
        n = n/2;
        if (k == 0)
         return 2;
    }
 
    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, store i and divide n
        while (n%i == 0)
        {
            if (k == 1)
              return i;
 
            k--;
            n = n/i;
        }
    }
 
    // This condition is to handle the case where
    // n is a prime number greater than 2
    if (n > 2 && k == 1)
        return n;
 
    return -1;
}
 
// Driver Program
int main()
{
    int n = 12, k = 3;
    cout << kPrimeFactor(n, k) << endl;
    n = 14, k = 3;
    cout << kPrimeFactor(n, k) << endl;
    return 0;
}


Java




// JAVA Program to print kth prime factor
import java.io.*;
import java.math.*;
 
class GFG{
     
    // A function to generate prime factors
    // of a given number n and return k-th
    // prime factor
    static int kPrimeFactor(int n, int k)
    {
        // Find the number of 2's that
        // divide k
        while (n % 2 == 0)
        {
            k--;
            n = n / 2;
            if (k == 0)
             return 2;
        }
      
        // n must be odd at this point.
        // So we can skip one element
        // (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i = i + 2)
        {
            // While i divides n, store i
            // and divide n
            while (n % i == 0)
            {
                if (k == 1)
                  return i;
      
                k--;
                n = n / i;
            }
        }
      
        // This condition is to handle the
        // case where n is a prime number
        // greater than 2
        if (n > 2 && k == 1)
            return n;
      
        return -1;
    }
      
    // Driver Program
    public static void main(String args[])
    {
        int n = 12, k = 3;
        System.out.println(kPrimeFactor(n, k));
        n = 14; k = 3;
        System.out.println(kPrimeFactor(n, k));
    }
}
 
/*This code is contributed by Nikita Tiwari.*/


Python3




# Python Program to print kth prime factor
import math
 
# A function to generate prime factors of a
# given number n and return k-th prime factor
def kPrimeFactor(n,k) :
 
    # Find the number of 2's that divide k
    while (n % 2 == 0) :
        k = k - 1
        n = n // 2
        if (k == 0) :
            return 2
  
    # n must be odd at this point. So we can
    # skip one element (Note i = i +2)
    i = 3
    while i <= math.sqrt(n) :
     
        # While i divides n, store i and divide n
        while (n % i == 0) :
            if (k == 1) :
                return i
  
            k = k - 1
            n = n // i
         
        i = i + 2
  
    # This condition is to handle the case
    # where n is a prime number greater than 2
    if (n > 2 and k == 1) :
        return n
  
    return -1
 
# Driver Program
n = 12
k = 3
print(kPrimeFactor(n, k))
 
n = 14
k = 3
print(kPrimeFactor(n, k))
 
# This code is contributed by Nikita Tiwari.


C#




// C# Program to print kth prime factor.
using System;
 
class GFG {
     
    // A function to generate prime factors
    // of a given number n and return k-th
    // prime factor
    static int kPrimeFactor(int n, int k)
    {
         
        // Find the number of 2's that
        // divide k
        while (n % 2 == 0)
        {
            k--;
            n = n / 2;
             
            if (k == 0)
                return 2;
        }
     
        // n must be odd at this point.
        // So we can skip one element
        // (Note i = i +2)
        for (int i = 3; i <= Math.Sqrt(n);
                                i = i + 2)
        {
             
            // While i divides n, store i
            // and divide n
            while (n % i == 0)
            {
                if (k == 1)
                    return i;
     
                k--;
                n = n / i;
            }
        }
     
        // This condition is to handle the
        // case where n is a prime number
        // greater than 2
        if (n > 2 && k == 1)
            return n;
     
        return -1;
    }
     
    // Driver Program
    public static void Main()
    {
         
        int n = 12, k = 3;
        Console.WriteLine(kPrimeFactor(n, k));
         
        n = 14; k = 3;
        Console.WriteLine(kPrimeFactor(n, k));
    }
}
 
// This code is contributed by nitin mittal.


PHP




<?php
// PHP Program to print kth prime factor
 
// A function to generate prime
// factors of a  given number n
// and return k-th prime factor
function kPrimeFactor($n, $k)
{
     
    // Find the number of 2's
    // that divide k
    while ($n%2 == 0)
    {
        $k--;
        $n = $n/2;
        if ($k == 0)
        return 2;
    }
 
    // n must be odd at this point.
    // So we can skip one element
    // (Note i = i +2)
    for($i = 3; $i <= sqrt($n); $i = $i+2)
    {
         
        // While i divides n,
        // store i and divide n
        while ($n % $i == 0)
        {
            if ($k == 1)
            return $i;
 
            $k--;
            $n = $n / $i;
        }
    }
 
    // This condition is to
    // handle the case where
    // n is a prime number
    // greater than 2
    if ($n > 2 && $k == 1)
        return $n;
 
    return -1;
}
 
// Driver Code
{
    $n = 12;
    $k = 3;
    echo kPrimeFactor($n, $k),"\n" ;
    $n = 14;
    $k = 3;
    echo kPrimeFactor($n, $k) ;
    return 0;
}
 
// This code contributed by nitin mittal.
?>


Javascript




<script>
 
// Javascript Program to print kth prime factor
 
    // A function to generate prime factors
    // of a given number n and return k-th
    // prime factor
    function kPrimeFactor(n, k)
    {
     
        // Find the number of 2's that
        // divide k
        while (n % 2 == 0)
        {
            k--;
            n = n / 2;
            if (k == 0)
             return 2;
        }
        
        // n must be odd at this point.
        // So we can skip one element
        // (Note i = i +2)
        for (let i = 3; i <= Math.sqrt(n); i = i + 2)
        {
         
            // While i divides n, store i
            // and divide n
            while (n % i == 0)
            {
                if (k == 1)
                  return i;
        
                k--;
                n = n / i;
            }
        }
        
        // This condition is to handle the
        // case where n is a prime number
        // greater than 2
        if (n > 2 && k == 1)
            return n;
        
        return -1;
    }
      
// Driver code   
 
    let n = 12, k = 3;
    document.write(kPrimeFactor(n, k) + "<br/>");
    n = 14; k = 3;
    document.write(kPrimeFactor(n, k));
             
// This code is contributed by susmitakundugoaldanga.
 
</script>


Output:  

3
-1

Time Complexity: O(?n log n) 
Auxiliary Space: O(1)

An Efficient Solution is to use Sieve of Eratosthenes. Note that this solution is efficient when we need k-th prime factor for multiple test cases. For a single case, previous approach is better. 
The idea is to do preprocessing and store least prime factor of all numbers in given range. Once we have least prime factors stored in an array, we can find k-th prime factor by repeatedly dividing n with least prime factor while it is divisible, then repeating the process for reduced n. 
 

C++




// C++ program to find k-th prime factor using Sieve Of
// Eratosthenes. This program is efficient when we have
// a range of numbers.
#include<bits/stdc++.h>
 
using namespace std;
const int MAX = 10001;
 
// Using SieveOfEratosthenes to find smallest prime
// factor of all the numbers.
// For example, if MAX is 10,
// s[2] = s[4] = s[6] = s[10] = 2
// s[3] = s[9] = 3
// s[5] = 5
// s[7] = 7
void sieveOfEratosthenes(int s[])
{
    // Create a boolean array "prime[0..MAX]" and
    // initialize all entries in it as false.
    vector <bool> prime(MAX+1, false);
 
    // Initializing smallest factor equal to 2
    // for all the even numbers
    for (int i=2; i<=MAX; i+=2)
        s[i] = 2;
 
    // For odd numbers less than equal to n
    for (int i=3; i<=MAX; i+=2)
    {
        if (prime[i] == false)
        {
            // s(i) for a prime is the number itself
            s[i] = i;
 
            // For all multiples of current prime number
            for (int j=i; j*i<=MAX; j+=2)
            {
                if (prime[i*j] == false)
                {
                    prime[i*j] = true;
 
                    // i is the smallest prime factor for
                    // number "i*j".
                    s[i*j] = i;
                }
            }
        }
    }
}
 
// Function to generate prime factors and return its
// k-th prime factor. s[i] stores least prime factor
// of i.
int kPrimeFactor(int n, int k, int s[])
{
    // Keep dividing n by least prime factor while
    // either n is not 1 or count of prime factors
    // is not k.
    while (n > 1)
    {
        if (k == 1)
          return s[n];
 
        // To keep track of count of prime factors
        k--;
 
        // Divide n to find next prime factor
        n /= s[n];
    }
 
    return -1;
}
 
// Driver Program
int main()
{
    // s[i] is going to store prime factor
    // of i.
    int s[MAX+1];
    memset(s, -1, sizeof(s));
    sieveOfEratosthenes(s);
 
    int n = 12, k = 3;
    cout << kPrimeFactor(n, k, s) << endl;
    n = 14, k = 3;
    cout << kPrimeFactor(n, k, s) << endl;
    return 0;
}


Java




// Java program to find k-th prime factor
// using Sieve Of Eratosthenes. This
// program is efficient when we have
// a range of numbers.
class GFG
{
static int MAX = 10001;
 
// Using SieveOfEratosthenes to find smallest prime
// factor of all the numbers.
// For example, if MAX is 10,
// s[2] = s[4] = s[6] = s[10] = 2
// s[3] = s[9] = 3
// s[5] = 5
// s[7] = 7
static void sieveOfEratosthenes(int []s)
{
     
    // Create a boolean array "prime[0..MAX]" and
    // initialize all entries in it as false.
    boolean[] prime=new boolean[MAX+1];
 
    // Initializing smallest factor equal to 2
    // for all the even numbers
    for (int i = 2; i <= MAX; i += 2)
        s[i] = 2;
 
    // For odd numbers less than equal to n
    for (int i = 3; i <= MAX; i += 2)
    {
        if (prime[i] == false)
        {
            // s(i) for a prime is the number itself
            s[i] = i;
 
            // For all multiples of current prime number
            for (int j = i; j * i <= MAX; j += 2)
            {
                if (prime[i * j] == false)
                {
                    prime[i * j] = true;
 
                    // i is the smallest prime factor for
                    // number "i*j".
                    s[i * j] = i;
                }
            }
        }
    }
}
 
// Function to generate prime factors
// and return its k-th prime factor.
// s[i] stores least prime factor of i.
static int kPrimeFactor(int n, int k, int []s)
{
    // Keep dividing n by least
    // prime factor while either
    // n is not 1 or count of
    // prime factors is not k.
    while (n > 1)
    {
        if (k == 1)
        return s[n];
 
        // To keep track of count of prime factors
        k--;
 
        // Divide n to find next prime factor
        n /= s[n];
    }
    return -1;
}
 
// Driver code
public static void main (String[] args)
{
     
    // s[i] is going to store prime factor
    // of i.
    int[] s = new int[MAX + 1];
    sieveOfEratosthenes(s);
 
    int n = 12, k = 3;
    System.out.println(kPrimeFactor(n, k, s));
    n = 14;
    k = 3;
    System.out.println(kPrimeFactor(n, k, s));
}
}
 
// This code is contributed by mits


Python3




# python3 program to find k-th prime factor using Sieve Of
# Eratosthenes. This program is efficient when we have
# a range of numbers.
 
MAX = 10001
 
# Using SieveOfEratosthenes to find smallest prime
# factor of all the numbers.
# For example, if MAX is 10,
# s[2] = s[4] = s[6] = s[10] = 2
# s[3] = s[9] = 3
# s[5] = 5
# s[7] = 7
def sieveOfEratosthenes(s):
 
# Create a boolean array "prime[0..MAX]" and
# initialize all entries in it as false.
    prime=[False for i in range(MAX+1)]
 
    # Initializing smallest factor equal to 2
    # for all the even numbers
    for i in range(2,MAX+1,2):
        s[i] = 2;
 
    # For odd numbers less than equal to n
    for i in range(3,MAX,2):
        if (prime[i] == False):
        # s(i) for a prime is the number itself
            s[i] = i
 
        # For all multiples of current prime number
            for j in range(i,MAX+1,2):
                if j*j> MAX:
                    break
                if (prime[i*j] == False):
                    prime[i*j] = True
 
                    # i is the smallest prime factor for
                    # number "i*j".
                    s[i*j] = i
 
# Function to generate prime factors and return its
# k-th prime factor. s[i] stores least prime factor
# of i.
def kPrimeFactor(n, k, s):
    # Keep dividing n by least prime factor while
    # either n is not 1 or count of prime factors
    # is not k.
    while (n > 1):
 
        if (k == 1):
            return s[n]
 
        # To keep track of count of prime factors
        k-=1
 
        # Divide n to find next prime factor
        n //= s[n]
 
 
    return -1
 
# Driver Program
 
# s[i] is going to store prime factor
# of i.
s=[-1 for i in range(MAX+1)]
 
sieveOfEratosthenes(s)
 
n = 12
k = 3
print(kPrimeFactor(n, k, s))
 
n = 14
k = 3
print(kPrimeFactor(n, k, s))
 
# This code is contributed by mohit kumar 29


C#




// C# program to find k-th prime factor
// using Sieve Of Eratosthenes. This
// program is efficient when we have
// a range of numbers and we
using System;
class GFG
{
static int MAX = 10001;
 
// Using SieveOfEratosthenes to find
// smallest prime factor of all the
// numbers. For example, if MAX is 10,
// s[2] = s[4] = s[6] = s[10] = 2
// s[3] = s[9] = 3
// s[5] = 5
// s[7] = 7
static void sieveOfEratosthenes(int []s)
{
    // Create a boolean array "prime[0..MAX]"
    // and initialize all entries in it as false.
    bool[] prime = new bool[MAX + 1];
 
    // Initializing smallest factor equal
    // to 2 for all the even numbers
    for (int i = 2; i <= MAX; i += 2)
        s[i] = 2;
 
    // For odd numbers less than equal to n
    for (int i = 3; i <= MAX; i += 2)
    {
        if (prime[i] == false)
        {
            // s(i) for a prime is the
            // number itself
            s[i] = i;
 
            // For all multiples of current
            // prime number
            for (int j = i; j * i <= MAX; j += 2)
            {
                if (prime[i * j] == false)
                {
                    prime[i * j] = true;
 
                    // i is the smallest prime factor
                    // for number "i*j".
                    s[i * j] = i;
                }
            }
        }
    }
}
 
// Function to generate prime factors
// and return its k-th prime factor.
// s[i] stores least prime factor of i.
static int kPrimeFactor(int n, int k, int []s)
{
    // Keep dividing n by least prime
    // factor while either n is not 1
    // or count of prime factors is not k.
    while (n > 1)
    {
        if (k == 1)
        return s[n];
 
        // To keep track of count of
        // prime factors
        k--;
 
        // Divide n to find next prime factor
        n /= s[n];
    }
 
    return -1;
}
 
// Driver Code
static void Main()
{
    // s[i] is going to store prime 
    // factor of i.
    int[] s = new int[MAX + 1];
    sieveOfEratosthenes(s);
 
    int n = 12, k = 3;
    Console.WriteLine(kPrimeFactor(n, k, s));
    n = 14;
    k = 3;
    Console.WriteLine(kPrimeFactor(n, k, s));
}
}
 
// This code is contributed by mits


PHP




<?php
// PHP program to find k-th prime factor
// using Sieve Of Eratosthenes. This program
// is efficient when we have a range of numbers.
 
$MAX = 10001;
 
// Using SieveOfEratosthenes to find
// smallest prime factor of all the numbers.
// For example, if MAX is 10,
// s[2] = s[4] = s[6] = s[10] = 2
// s[3] = s[9] = 3
// s[5] = 5
// s[7] = 7
function sieveOfEratosthenes(&$s)
{
    global $MAX;
     
    // Create a boolean array "prime[0..MAX]"
    // and initialize all entries in it as false.
    $prime = array_fill(0, $MAX + 1, false);
 
    // Initializing smallest factor equal
    // to 2 for all the even numbers
    for ($i = 2; $i <= $MAX; $i += 2)
        $s[$i] = 2;
 
    // For odd numbers less than equal to n
    for ($i = 3; $i <= $MAX; $i += 2)
    {
        if ($prime[$i] == false)
        {
            // s(i) for a prime is the
            // number itself
            $s[$i] = $i;
 
            // For all multiples of current
            // prime number
            for ($j = $i; $j * $i <= $MAX; $j += 2)
            {
                if ($prime[$i * $j] == false)
                {
                    $prime[$i * $j] = true;
 
                    // i is the smallest prime
                    // factor for number "i*j".
                    $s[$i * $j] = $i;
                }
            }
        }
    }
}
 
// Function to generate prime factors and
// return its k-th prime factor. s[i] stores
// least prime factor of i.
function kPrimeFactor($n, $k, $s)
{
    // Keep dividing n by least prime
    // factor while either n is not 1
    // or count of prime factors is not k.
    while ($n > 1)
    {
        if ($k == 1)
        return $s[$n];
 
        // To keep track of count of
        // prime factors
        $k--;
 
        // Divide n to find next prime factor
        $n = (int)($n / $s[$n]);
    }
 
    return -1;
}
 
// Driver Code
 
// s[i] is going to store prime
// factor of i.
$s = array_fill(0, $MAX + 1, -1);
sieveOfEratosthenes($s);
 
$n = 12;
$k = 3;
print(kPrimeFactor($n, $k, $s) . "\n");
 
$n = 14;
$k = 3;
print(kPrimeFactor($n, $k, $s));
 
// This code is contributed by chandan_jnu
?>


Javascript




<script>
 
// Javascript program to find k-th prime factor
// using Sieve Of Eratosthenes. This
// program is efficient when we have
// a range of numbers.
 
var MAX = 10001;
 
// Using SieveOfEratosthenes to find smallest prime
// factor of all the numbers.
// For example, if MAX is 10,
// s[2] = s[4] = s[6] = s[10] = 2
// s[3] = s[9] = 3
// s[5] = 5
// s[7] = 7
function sieveOfEratosthenes(s)
{
     
    // Create a boolean array "prime[0..MAX]" and
    // initialize all entries in it as false.
    prime=Array.from({length: MAX+1}, (_, i) => false);
 
    // Initializing smallest factor equal to 2
    // for all the even numbers
    for (i = 2; i <= MAX; i += 2)
        s[i] = 2;
 
    // For odd numbers less than equal to n
    for (i = 3; i <= MAX; i += 2)
    {
        if (prime[i] == false)
        {
            // s(i) for a prime is the number itself
            s[i] = i;
 
            // For all multiples of current prime number
            for (j = i; j * i <= MAX; j += 2)
            {
                if (prime[i * j] == false)
                {
                    prime[i * j] = true;
 
                    // i is the smallest prime factor for
                    // number "i*j".
                    s[i * j] = i;
                }
            }
        }
    }
}
 
// Function to generate prime factors
// and return its k-th prime factor.
// s[i] stores least prime factor of i.
function kPrimeFactor(n , k , s)
{
    // Keep dividing n by least
    // prime factor while either
    // n is not 1 or count of
    // prime factors is not k.
    while (n > 1)
    {
        if (k == 1)
        return s[n];
 
        // To keep track of count of prime factors
        k--;
 
        // Divide n to find next prime factor
        n /= s[n];
    }
    return -1;
}
 
// Driver code
 
// s[i] is going to store prime factor
// of i.
var s = Array.from({length: MAX + 1}, (_, i) => 0);
sieveOfEratosthenes(s);
 
var n = 12, k = 3;
document.write(kPrimeFactor(n, k, s)+"<br>");
n = 14;
k = 3;
document.write(kPrimeFactor(n, k, s));
 
 
 
// This code contributed by shikhasingrajput
 
</script>


Output:  

3
-1

Time Complexity: O(n*log(log(n))) 
Auxiliary Space: O(n)

 



Previous Article
Next Article

Similar Reads

Count numbers in a given range having prime and non-prime digits at prime and non-prime positions respectively
Given two integers L and R, the task is to find the count of numbers in the range [L, R] having prime digits at prime positions and non-prime digits at non-prime positions. Examples: Input: L = 5, R = 22 Output: 7Explanation: The numbers 6, 8, 9, 12, 13, 15, and 17 have prime digits at prime positions and non-prime digits at non-prime positions. In
15 min read
N-th prime factor of a given number
Given Q queries which consist of two integers, one is number(1 &lt;= number &lt;= 106) and the other is N., the task is to find the N-th prime factor of the given number. Examples: Input: Number of Queries, Q = 4 number = 6, N = 1 number = 210, N = 3 number = 210, N = 2 number = 60, N = 2Output: 2 5 3 2 Explanations: For number = 6, The prime facto
15 min read
Sum of largest prime factor of each number less than equal to n
Given a non-negative integer n. The problem is to find the sum of the largest prime factor of each number less than equal to n. Examples: Input : n = 10 Output : 32 Largest prime factor of each number Prime factor of 2 = 2 Prime factor of 3 = 3 Prime factor of 4 = 2 Prime factor of 5 = 5 Prime factor of 6 = 3 Prime factor of 7 = 7 Prime factor of 8
8 min read
Python Program for Find largest prime factor of a number
Given a positive integer \'n\'( 1 &lt;= n &lt;= 1015). Find the largest prime factor of a number. Input: 6 Output: 3 Explanation Prime factor of 6 are- 2, 3 Largest of them is 3 Input: 15 Output: 5 C/C++ Code # Python3 code to find largest prime # factor of number import math # A function to find largest prime factor def maxPrimeFactors (n): # Init
3 min read
Find sum of a number and its maximum prime factor
Given an integer N, the task is to find the sum of N and it's maximum prime factor.Examples: Input: 19 Output: 38 Maximum prime factor of 19 is 19. Hence, 19 + 19 = 38Input: 8 Output: 10 8 + 2 = 10 Approach: Find the largest prime factor of the number and store it in maxPrimeFact then print the value of N + maxPrimeFact.Below is the implementation
6 min read
Sum of Maximum and Minimum prime factor of every number in the Array
Given an array arr[], the task is to find the sum of the maximum and the minimum prime factor of every number in the given array.Examples: Input: arr[] = {15} Output: 8 The maximum and the minimum prime factors of 15 are 5 and 3 respectively.Input: arr[] = {5, 10, 15, 20, 25, 30} Output: 10 7 8 7 10 7 Approach: The idea is to use Sieve of Eratosthe
9 min read
Find largest prime factor of a number
Given a positive integer 'n'( 1 &lt;= n &lt;= 1015). Find the largest prime factor of a number. Input: 6Output: 3ExplanationPrime factor of 6 are- 2, 3Largest of them is '3'Input: 15Output: 5Recommended PracticeLargest prime factorTry It!Method 1:The approach is simple, just factorize the given number by dividing it with the divisor of a number and
11 min read
Find the total number of composite factor for a given number
Given an integer N, the task is to find the total number of composite factors of N. Composite factors of a number are the factors which are not prime.Examples: Input: N = 24 Output: 5 1, 2, 3, 4, 6, 8, 12 and 24 are the factors of 24. Out of which only 4, 6, 8, 12 and 24 are composites.Input: N = 100 Output: 6 Approach: Find all the factors of N an
6 min read
Numbers with sum of digits equal to the sum of digits of its all prime factor
Given a range, the task is to find the count of the numbers in the given range such that the sum of its digit is equal to the sum of all its prime factors digits sum.Examples: Input: l = 2, r = 10 Output: 5 2, 3, 4, 5 and 7 are such numbers Input: l = 15, r = 22 Output: 3 17, 19 and 22 are such numbers As, 17 and 19 are already prime. Prime Factors
13 min read
Count all the numbers less than 10^6 whose minimum prime factor is N
Given a number N which is prime. The task is to find all the numbers less than or equal to 10^6 whose minimum prime factor is N.Examples: Input: N = 2 Output: 500000 Input: N = 3 Output: 166667 Approach: Use sieve of Eratosthenes to find the solution to the problem. Store all the prime numbers less than 10^6 . Form another sieve that will store the
7 min read