1. Write a function named factors that returns all prime factors of an integer. For example,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Write a function named factors that returns all prime factors of an integer. For example, factors(12) returns [2,2,3]. If the input is a prime or 1 it returns an empty list. The factors should be listed in increasing order. Please do not search or copy from the internet. You can orally discuss solutions with other students, but any collaboration that involves writing things down will be considered as cheating and earn a zero credit. If you are stuck, please talk to the instructor. Python does not limit the size of the integers so you can run it on arbitrarily large integers (bignums). 2. In the report, include the code and a derivation of the running time of your algorithm (a) assuming that multiplications and division (and additions) take constant time and (b) assuming that multiplication and division of n-bit numbers take O(n²) time and additions and subtractions take O(n) time. 3. The size of the input n is usually measured by the number of bits needed to represent the input. But here we can use decimal digits since it is directly proportional to the bits. Give a table T(n) vs. n from your experimental results. Does your table closely match one of the running time functions derived in 2? How large can n be so that T(n) is approximately 5 minutes. What if T(n) is 5 hours? 5 days? Factoring is a fundamental crypto-primitive that underlies modern cryptography. What size of n makes it practically impossible for your algorithm to factorize, e.g., T(n) > 10 years. 4. State a useful invariant of the loop towards proving the correctness of the algorithm. 5. Prove that the algorithm is correct using your previously defined invariant. 1. Write a function named factors that returns all prime factors of an integer. For example, factors(12) returns [2,2,3]. If the input is a prime or 1 it returns an empty list. The factors should be listed in increasing order. Please do not search or copy from the internet. You can orally discuss solutions with other students, but any collaboration that involves writing things down will be considered as cheating and earn a zero credit. If you are stuck, please talk to the instructor. Python does not limit the size of the integers so you can run it on arbitrarily large integers (bignums). 2. In the report, include the code and a derivation of the running time of your algorithm (a) assuming that multiplications and division (and additions) take constant time and (b) assuming that multiplication and division of n-bit numbers take O(n²) time and additions and subtractions take O(n) time. 3. The size of the input n is usually measured by the number of bits needed to represent the input. But here we can use decimal digits since it is directly proportional to the bits. Give a table T(n) vs. n from your experimental results. Does your table closely match one of the running time functions derived in 2? How large can n be so that T(n) is approximately 5 minutes. What if T(n) is 5 hours? 5 days? Factoring is a fundamental crypto-primitive that underlies modern cryptography. What size of n makes it practically impossible for your algorithm to factorize, e.g., T(n) > 10 years. 4. State a useful invariant of the loop towards proving the correctness of the algorithm. 5. Prove that the algorithm is correct using your previously defined invariant.
Expert Answer:
Answer rating: 100% (QA)
Answer Python Code for Prime Factorization def factorsn primefactors divisor 2 while n 1 while n div... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Khairul has been working with Tun Hamid Energy Bhd since 1 February 2009 as a Human Resource Executive. Beginning 1 January 2014, he was promoted as Human Resource Manager. Details of his...
-
1. A long-term asset is recorded at the: a. Cost of the asset. b. Additional costs to get the asset ready for use. c. Cost of the asset plus all costs necessary to the asset ready for use. d. Cost of...
-
Refer to the information in problem 37. Determine Warner Corporations income tax liability. Problem 37. The Warner Corporation has gross income of $560,000. It has business expenses of $325,000, a...
-
A project has been selected for implementation. The net cash flow (NCF) profile associated with the project is shown below. MARR is 10 percent/year. a. What is the internal rate of return of this...
-
Select the graph that matches the numbered manufacturing cost data. Indicate by letter which graph best fits the situation or item described. The vertical axes of the graphs represent total cost and...
-
7. 5 What is 11. as an improper fraction? 16 Answer: 17 9 - 8. Which is the difference of 32 32 in lowest terms? 9 18 1 8 32 1 9. 8 5 3 + Which is the quotient of 12 10? 1 18 1 10. What is 25 as a...
-
The G. Saussy Manufacturing company is putting out four new electronic components. Each of Saussy's four plants has the capacity to add one more product to its current line of electronic parts. The...
-
Organizational success depends on well-crafted vision and mission statements, which serve as frames and guardrails for making strategic decisions. Create an initial post by: Addressing Theme 1 by:...
-
What type of mutual fund focuses on investing in stocks of companies with high growth potential? Question 32Answer a. Money market fund b. Bond fund c. Index fund d. Growth fund
-
state two aspects of the finance world that you find to be socially unjust. Importantly, state WHY you think it violates social justice.
-
One of the methods that allows individual investors to gain exposure to commodities without directly owning physical assets is: Question 13Answer a. Commodity futures b. Exchange-traded funds (ETFs)...
-
Under current guidance are broker-dealers required to risk assess all third parties who use any confidential client information in the course of the services provided?
-
swanson's expects a 9.0% increase in sales over last year's volume of $230000. Last year, 20% of sales occurred in May. Calculate the planned sales of May keeping in mind that this May has 22 selling...
-
Find all the local minim4, local of the manima and function? f lu, 4) saddle paint 2xy-5x2-2y%+4u+4y-4
-
Fill in each blank so that the resulting statement is true. A solution to a system of linear equations in two variables is an ordered pair that__________ .
-
These are the rules that must be followed when writing a program. a. Syntax b. Punctuation c. Key words d. Operators
-
True or False Variable names can have spaces in them.
-
What is the purpose of the self parameter in a method?
-
Salen Company finances some of its current operations by assigning accounts receivable to a finance company. On July 1, 2015, it assigned, under guarantee, specific accounts amounting to 150,000,000....
-
Bill Jovi is reviewing the cash accounting for Nottleman, Inc., a local mailing service. Jovis review will focus on the petty cash account and the bank reconciliation for the month ended May 31,...
-
On October 1, 2015, Arden Farm Equipment Company sold a pecan-harvesting machine to Valco Brothers Farm, Inc. In lieu of a cash payment Valco Brothers Farm gave Arden a 2-year, $120,000, 8% note (a...
Study smarter with the SolutionInn App