Question

Use python for programming the fundamental theorem of arithmetic (single factorization theorem), which affirms that every...

Use python for programming the fundamental theorem of arithmetic (single factorization theorem), which affirms that every positive integer greater than 1 is a prime number or a single product of prime numbers.

Show the factors in a list and show a dictionary where the keys are the factors of the number entered and the values are how many times each factor appears in the unique combination.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#Python program

import math

def primeFactors(n):
    dist = {}
    while n % 2 == 0:
        if 2 in dist:
            dist[2] = dist[2] + 1
        else:
            dist[2] = 1
        n = n / 2
        
    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i== 0:
            if i in dist:
                dist[i] = dist[i] + 1
            else:
                dist[i] = 1
          
            n = n / i
            
    if n > 2:
        if n in dist:
                dist[n] = dist[n] + 1
        else:
            dist[n] = 1

    return dist


dic = primeFactors(100)

for i in dic:
    print(i , ' = ', dic[i])


#Screenshot

Run Options Window Help File Edit Format import math def prime Factors (n): dist = {} while n x 2 == 0: if 2 in dist: dist[2]

Add a comment
Know the answer?
Add Answer to:
Use python for programming the fundamental theorem of arithmetic (single factorization theorem), which affirms that every...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be...

    (Python) (15 points) Fundamental theorem of number theory states that every natural number n can be expressed as a product of prime numbers, called its prime factorization. E.g. 15 3 x 5,20 2x 2x5. You are required to write a Python function prime factors(n) which accepts a natural number as the input argument and returns a list of all the prime factors of n in ascending order. (Use 20, 666, 4020 to test your program.) 2.

  • the <stdbool.h> library might be useful. Also, you might need to define TRUE and FALSE to...

    the <stdbool.h> library might be useful. Also, you might need to define TRUE and FALSE to be 1 and 0, respectively 2. filename: factorization.c (use factorization.out with input files factorization_input1, factorization_input2) In many cases, it is not enough to know whether a number is prime; sometimes, you need to know its factors. Every positive integer greater than 1 can be expressed as a product of prime numbers. This factorization is unique and is called the prime factorization. For example, the...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

  • 1-5 theorem, state it. Define all terms, e.g., a cyclic group is generated by a single...

    1-5 theorem, state it. Define all terms, e.g., a cyclic group is generated by a single use a element. T encourage you to work together. If you find any errors, correct them and work the problem 1. Let G be the group of nonzero complex numbers under multiplication and let H-(x e G 1. (Recall that la + bil-b.) Give a geometric description of the cosets of H. Suppose K is a proper subgroup of H is a proper subgroup...

  • please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02:...

    please use c++ programming and single dimensional arrays to solve this problem thank you Problem 02: Large Integer (20 points) In CH, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an...

  • In the following problem, we will work through a proof of an important theorem of arithmetic. Your job will be to read the proof carefully and answer some questions about the argument. Theorem (The Di...

    In the following problem, we will work through a proof of an important theorem of arithmetic. Your job will be to read the proof carefully and answer some questions about the argument. Theorem (The Division Algorithm). For any integer n ≥ 0, and for any positive integer m, there exist integers d and r such that n = dm + r and 0 ≤ r < m. Proof: (By strong induction on the variable n.) Let m be an arbitrary...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • I have to use the following theorems to determine whether or not it is possible for...

    I have to use the following theorems to determine whether or not it is possible for the given orders to be simple. Theorem 1: |G|=1 or prime, then it is simple. Theorem 2: If |G| = (2 times an odd integer), the G is not simple. Theorem 3: n is an element of positive integers, n is not prime, p is prime, and p|n. If 1 is the only divisor of n that is congruent to 1 (mod p) then...

  • In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer...

    In python please 6 annoying_int_sequence(n) In annoying_recursion.py, write the function annoying_int_sequence(n) which takes a single integer parameter (which must be non-negative). It must return a list of intgers. The contents of the integers are defined recursively. Basically, each version of this sequence is made up of the next-smaller one, repeated n times - and with the number n in-between. For instance, the sequence for n = 3 is: ???? 3 ???? 3 ???? Just drop in the the sequence for...

  • 6. [R Programming| In order to complete this question, we will need to use a fundamen-...

    6. [R Programming| In order to complete this question, we will need to use a fundamen- tal theorem in probabilty theory known as the (Weak) Law of Large Numbers (WLLN) The WLLN will be covered in greater detail in Chapter 8, however we will use this key result throughout the course to approximate probabilities that are otherwise difficult to calculate theoretically. A simplified version of the theorem goes as follows. Assume we are interested in com- puting the probability of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT