Answers for "prime factors of number python"

3

prime factorization python

import math


def primeFactors(n):
    # no of even divisibility
    while n % 2 == 0:
        print(2)
        n = n / 2
    # n reduces to become odd
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        # while i divides n
        while n % i == 0:
            print(i)
            n = n / i
    # if n is a prime
    if n > 2:
        print(n)


primeFactors(256)
Posted by: Guest on November-26-2020
-2

to find factors of a number in python

# Python Program to find the factors of a number

# This function computes the factor of the argument passed
def print_factors(x):
   print("The factors of",x,"are:")
   for i in range(1, x + 1):
       if x % i == 0:
           print(i)

num = 6

print_factors(num)
Posted by: Guest on November-03-2020
1

python find factors of a number

def factors(n):
    return set(reduce(list.__add__, 
        ([i, n//i] for i in range(1, int(n**0.5) + 1) if not n % i )))
Posted by: Guest on October-20-2020

Code answers related to "prime factors of number python"

Python Answers by Framework

Browse Popular Code Answers by Language