Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python Least prime factor of numbers till n

# Python 3 program to print the
# least prime factors of numbers
# less than or equal to n using
# modified Sieve of Eratosthenes
 
def leastPrimeFactor(n) :
     
    # Create a vector to store least primes.
    # Initialize all entries as 0.
    least_prime = [0] * (n + 1)
 
    # We need to print 1 for 1.
    least_prime[1] = 1
 
    for i in range(2, n + 1) :
         
        # least_prime[i] == 0
        # means it i is prime
        if (least_prime[i] == 0) :
             
            # marking the prime number
            # as its own lpf
            least_prime[i] = i
 
            # mark it as a divisor for all its
            # multiples if not already marked
            for j in range(i * i, n + 1, i) :
                if (least_prime[j] == 0) :
                    least_prime[j] = i
         
         
    # print least prime factor
    # of numbers till n
    for i in range(1, n + 1) :
        print("Least Prime factor of "
              ,i , ": " , least_prime[i] )
         
 
# Driver program
 
n = 10
leastPrimeFactor(n)
 
 
# This code is contributed
# by Nikita Tiwari.
Comment

PREVIOUS NEXT
Code Example
Python :: How to sort a list by even or odd numbers using a filter? 
Python :: choose what items on python 
Python :: keep 0 in front of number pandas read csv 
Python :: page views count django 
Python :: Location of INSTALLED_APP and MIDDLEWARE 
Python :: change value of element 
Python :: Mirror Inverse Program in python 
Python :: django not configured pylint error fix 
Python :: check true false in python 
Python :: python backtest 
Python :: Function argument unpacking in python 
Python :: Uploading small amounts of data into memory 
Python :: database setup in django aws 
Python :: first flask api 
Python :: await not working python 
Python :: tweepy to dataframe 
Python :: python return multiple value from a function using a dictionary 
Python :: Dizideki en son elemani alma 
Python :: python solve rubicks cube 
Python :: the best ide for python 
Python :: how to save all countries from a list in a database python 
Python :: python selenium disable JavaScript Detection 
Python :: cudf - merge dataframes 
Python :: vbscript shutdown remote computer 
Python :: pyqt message box set information text 
Python :: online python text editor 
Python :: wait until you press escape 
Python :: Python Pipelining Generators 
Python :: Errors that you will get during date object in python datetime 
Python :: Histograms without overlapping bars 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =