python prime factors

Solutions on MaxInterview for python prime factors by the best coders in the world

showing results for - "python prime factors"
Tess
03 Apr 2018
1import math
2
3
4def primeFactors(n):
5    # no of even divisibility
6    while n % 2 == 0:
7        print(2)
8        n = n / 2
9    # n reduces to become odd
10    for i in range(3, int(math.sqrt(n)) + 1, 2):
11        # while i divides n
12        while n % i == 0:
13            print(i)
14            n = n / i
15    # if n is a prime
16    if n > 2:
17        print(n)
18
19
20primeFactors(256)
Lilie
05 Apr 2019
1# There is no quick way to calculate the prime factors of a number.
2# In fact, prime factorization is so famously hard that it's what puts the "asymmetric" in asymmetric RSA encryption.
3# That being said, it can be sped up a little bit by using divisibility rules, like checking if the sum of the digits is divisible by 3.
4
5def factors(num):
6        ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149] # Primes from https://primes.utm.edu/lists/small/10000.txt. Primes can also be generated by iterating through numbers and checking for factors, or by using a probabilistic test like Rabin-Miller.
7        pdict = {}
8        for p in ps:
9                if p <= num:
10                        while (num / p).is_integer():
11                                if str(p) in pdict:
12                                        pdict[str(p)] += 1
13                                else:
14                                        pdict[str(p)] = 1
15                                num /= p
16                if num == 1: break
17        return pdict
18
19# Returns a dictionary in the form {"base": "exponent"}
queries leading to this page
get greated prime factors of a number in phytoncalculate prime factors of a number pythonprime factors of number pythonreturn prime factors pythonhow to make a prime factorisation program pythonget all prime factors of a number pythonpython print prime factorialhow to generate prime factors using python generator 2aprime factorization in pythonbest way to find prime factorization in pythonpython prime factorswrite a function that returns the prime factors of a given integer 28between 1 and 10000 29 as a list prime factors in python inbuiltprint all prime divisors of a numberpython prime factorizehow to find prime factors pythonhow to get prime factorsof number in pythonpython most efficient way to get prime factors of numbernumber of prime factors pythonpython find prime factorprime factorial program in pythonpython prime factor functionif prime display it as prime if not prime find its prime divisor in pythonprime factorization algorithm pythonwrite a python script to find out prime factors of an integer numberprime factor pythonpython prime factorial for loopfind the prime factor pythonpython find all prime factors of numberis there a quick way to find prime factors in pythonhow to find all prime factors of a number in pythona function in python that returns the prime factors of a given number within 0 5 secondsfastest way to calculate prime factorisation pythonprint all prime factors of a given numberprime factorial logic pythonfunction to return prime factors of a number in pythpython prime factorizationpython prime factorisationlowest prime factors python programpython program to compute prime factors of an integervery short code for prime factors of a number pythonprime factors pthonpython package to find prime factors of a numberhow to find prime factorization in pythonprime factors python short codepython script to find prime factorisationwrite a program that displays the prime factors of an integer entered by the userprime factors of and y rating pythonprime factor algorithm pythonpython prime checkamount of prime factors pythonprime factors of a number in pythonprime factorization class pythonnumber of prime divisors of n pythonpython program to get all primefactorsprint out the prime factors of a numberprime factors python programefficient way to calculate total number of prime factors of a numberpython get prime factors of numberwrite a program in python to find prime factors of a given integer prime factors in pythonprikme factors in pythonpython calculate prime factorshow to find prime factors of anumber pythonprime factors calculator pythonfind prime factors of a number pythonhow to find al the prime factors of a number in pythonpython get prime factors in numpypython get prime factorsprime factorization using python in pythonfind prime factors of numberpython method for displaying all prime factors print prime factors of a number pythonmore prime factors pythonhow to break down a number into factors in pythonprime factors of number in optimized way pythondefine a function to print the prime factors of a number prime factorization in pythonprime factors using pythonfind all prime factors pythonpython factorial primespython efficient prime factorizationhow to find all the prime factors of a number in pyhtonshortest python code to find prime factors of a numberfind prime factorization pythonpython library prime factorhow to see a number prime factors in pythonpython prime factorization functionshow to calculate prime factors of a number in pythonfunction to return prime factors of a numberprime factor program in pythonprime factorization of a number in pythonpython find all prime factors that divide a numberall prime factors of a number formulafind all prime factors of a number in pythonprogram to find prime factors of a number in pythonprime factors logic in pythonpython3 prime factorization functionmethod to find prime factors of a number pythonhow to get prime factors of a number in pythonprime factorisation in pythonwhat is a prime factorizationleonardo 27s prime factors solution in pythonfind prime factors in pythomwrite a program to find prime factor of a number if a factor of a number is prime number then it is its prime factor c 2b 2bpython prime factors librarypython code to find prime factors of a numberprime factorization program in pythoncode parsing to prime factors in pythonpython program for finding prime number factors of a numberwrite a program to find out the prime factors of a number in pythonget prime factors of a number pythonfind prime factorization of a number pythonhow to prime factorize in pythonprime factorisation python gfgnumbers with 1 factors only cpphow to find the prime factors of a number in pythonpython factor with prime numbershow to print prime factors of a number in pythonprint prime factors of a number in pythonprime factorize function pythonhow to get prime factors of number in pythonfind prime factors of a number pypython prime factorize for looppython find prime divisorsprime factors function in pythonhow to get a number in its prime factor form using pythonprime factors fast pythonprime number pythonefficient way to calculate number of prime factors of a numberhow to find prime factors in pythondisplays all prime factors in pythonall prime factors of numberpython prime factors of a numberprime factors pythonfind prime factors of numer pythonprime factors program in pythonprime factors of a number pythonpython get prime factors of a numberhow to print prime factorization of a numbers in pythonpython program prime factorizationgiven a number check prime factors python 5cfind prime factors pythonfunction to return prime factors of a number in pythonhow to find the prime factors of a number pythopython program to get all prime factorsfactoring numbers into their prime factors pythonfinding prime factors of a number in pythonfind prime factors of a number in pythonprime number factorization pythonprime factorisation of a factorial pythonpython prime factorization libraryprogram to find prime factors of a number in pyhtonfind prime factors of a number geeksforgeekspython return prime factorsprime factorization method in pythonhow to do prime factorization pythonwrite a python program to print the prime factors of an integer prime factorization in python gfgprime factor in pythonfind prime factors in pythonprint prime factors of number pythonhow to find prime factors of a number in pythonprime factors code in pythonpython prime number factorizationfinding prime factors pythonprime factors number pythongenerate prime factors of a given integerprime factorization inpythonprogram for calculating prime factorspython code to get prime factors of a numberpythong get prime factor of numbergetting prime factors of a number in pythonhow to find prime factorization of number 10 in pythonhow to find the prime factor pythonc 2b 2b prime factorizationcount prime factors pythonprime factor finder using pythonpython program to find the prime factors of a huge numberprime factorization python codehow to find the prime divisors of a numberin pythonprime factor number program in pythondefine a function to print the prime factors of a number c 2b 2bgenerate prime factorization of a anumber gfgprime factorization pythonhow to find the the prime factorization in pythonprime factors in pythonmath python prime factorreturn all prime factorsfinding a number prime divisor pythonhow to get prime factors of a number pythonfind the multiples of a prime in pythonprime factorization python programhow to get prime factorization in pythonwrite a python program to print the prime factors of the given number given a number n 2c print its prime factorization pythonpython all prime factorial for loopprime factorization of numbeer pythonhow to get all prime factors of a number in pypython factor primeprogram to print prime factor in pythonfastest way to find all prime factors of a number pythonpython prime factorprove prime factor pythonprime factorization program pythonprime factors of a number using pythonto compute prime factors of an integer in pythonprime factorisation algorithm pythonprime favtorization of a number pythoninbuilt method to find prime factors of a number in pythonhow to get prime factors in pythonfinding the prime factors of a number in python efficientpython get prime factors built inpython code to calculate prime factorsprime factors of a given number in pythonpython program to find prime factors of a numberprime factoring algorithm pythonprime factorizor pythonhow to print allprime factors of a numberpython prime factorization functionpython computer prime factorshow to find all prime factors of a numbwrehow to find primefactors in pythonhow to find prime factorial of number 10 in pythonfactorization code pythonhow to find prime divisor of any number in pythonget prime factors pythonprime factorisation of a number pythonpython factoring out prime numberscount number of prime factors pythonprime factors of a number in python by user inputprime factorizationrun write a code that print out prime factorsread a number and display its prime factors in pythonpython inbuilt to get prime factorspython find prime factorsfind prime factors of a number with memoization pythonfind all prime factors of a number pythonpython prime factorialpython function to find prime factors of a numberget prime factors of a numberfinding prime factors in pythonpython program to print prime factors of a numberpython prime factor decompositionprogram for prime factors in cprime factorizer pythonfind the prime factors of number pythonwhat are prime factors in pythonrun write a python code that print out prime factorsprime factorizing algorithm pythonfinding prime factors of a number pythonprime factors in list pythondetermine prime factors of number in pythonprime factorisation of n 21 pythonprime factors in python using for loopget prime factros pythonprime factors of number in pythonprime factors in python in sympyprime factorization of a number pythonpython program for find prime factor of a numberpython prime factors calculatorfind out all the prime divisors pythonprme factorization of number coeeprime factorization c 2b 2b package write a program to find out the prime factors of a number example 3a prime factors of 56 2 2c 2 2c 2 2c 7checking for prime factors in pythnohow to find all the prime factors of a number in pythongenerate all prime factors of n pythonfind prime factors formula pythonpython prime factors