Write a Python script that consists of a single function definition: a function named cubes_mod_n that...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a Python script that consists of a single function definition: a function named cubes_mod_n that accepts a single integer n (assumed to be positive). The function returns a sorted list (from least to greatest) consisting of the cubes mod n, without repeats. If the integer 4 were passed in to the function, the list returned would be equal to [0, 1, 3]. If the integer 12 were passed in to the function, the list returned would be equal to [0, 1, 3, 4, 5, 7, 8, 9, 11]. If the integer 14 were passed in to the function, the list returned would be equal to [0, 1, 6, 7, 8, 13]. (The cubes mod n are the integers m satisfying 0 ≤ m <n-1 for which there exists an integer k satisfying k³ = m mod n. Note that we may restrict our attention to 0 ≤ k ≤n-1. For example, 12 is a cube mod 19 because 15³ mod 19 = 12. However, 2 is not a cube mod 4 because no integer (from 0 to 3 inclusive), when cubed, leaves a remainder of 2 when divided by 4. Write a Python script that consists of a single function definition: a function named cubes_mod_n that accepts a single integer n (assumed to be positive). The function returns a sorted list (from least to greatest) consisting of the cubes mod n, without repeats. If the integer 4 were passed in to the function, the list returned would be equal to [0, 1, 3]. If the integer 12 were passed in to the function, the list returned would be equal to [0, 1, 3, 4, 5, 7, 8, 9, 11]. If the integer 14 were passed in to the function, the list returned would be equal to [0, 1, 6, 7, 8, 13]. (The cubes mod n are the integers m satisfying 0 ≤ m <n-1 for which there exists an integer k satisfying k³ = m mod n. Note that we may restrict our attention to 0 ≤ k ≤n-1. For example, 12 is a cube mod 19 because 15³ mod 19 = 12. However, 2 is not a cube mod 4 because no integer (from 0 to 3 inclusive), when cubed, leaves a remainder of 2 when divided by 4.
Expert Answer:
Answer rating: 100% (QA)
Heres a Python script that defines the requested function def cubesmodnn ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Staywell finds and manages accommodation for owners of student accommodation in the Seattle Area. The company rents out and helps to maintain 1-5-bedroom properties located in two main areas in the...
-
Quality Air Conditioning manufactures three home air conditioners: an economy model, a standard model, and a deluxe model. The profits per unit are $63, $95, and $135, respectively. The production...
-
Name the five types of oil and gas traps shown in Fig. 7.3
-
Find the equation of each of the circles from the given information. Tangent to both axes and the lines y = 4 and x = 4
-
Osteoporosis is a disease that primarily affects postmenopausal women, causing decreased bone density and brittle bones that are vulnerable to fracture. The hormone calcitonin is sometimes used to...
-
One year ago, Tyler Stasney founded Swift Classified Ads. Stasney remembers that you took an accounting course while in college and comes to you for advice. He wishes to know how much net income his...
-
Provide in child care services 1 example of how you used, stored and labelled dangerous products according to manufacturer's instructions, service policies and procedures and regulation?
-
REPCO performs warranty repair work for name-brand kitchen appliances. REPCO bills appliance manufacturers on a costplus basis. It has a job-costing system that computes the cost of each order by...
-
Ambroses utility is U(x 1 , x 2 ) = 4x 1/2 + x 2 . If the price of nuts (good 1) is $1, the price of berries (good 2) is $4, and his income is $104, how many units of nuts will Ambrose choose?...
-
A square - section test piece is being used in a tensile test. The width and breadth of the test piece are each 15 mm. Calculate the stress in the test piece when a load of 3150 N is applied.
-
Assume the following economy produces only skateboards and the year 1981 is the base year. . Year Quantity Produced Price 1981 75 $30 1982 100 $33 1983 125 $38 1984 150 $42 What is the nominal GDP...
-
A force of 1 Newton will cause a mass of 1 kg to have an acceleration of 1 m/s 2 . Thus it follows that a force of 5 Newtons applied to a mass of 5 kg will cause it to acquire an acceleration of?...
-
What is the impact on the accounting if the company is not a going concern?
-
How Artificial Intelligence can be used to improve returning in supply chain? Explain
-
When price rises from $10 to $15, the quantity demanded decreases from 100 to 70. Calculate the price elasticity of demand using the midpoint formula.
-
Modify the CYK algorithm so that it applies to any CFG, not just those in CNF.
-
What will the following code display? mystring = 'abcdefg' print(mystring[:])
-
What part of the computer formats and presents data for people or other devices?
-
What will the following code display? numbers = [1, 2, 3, 4, 5] my_list = numbers[1:] print(my_list)
-
How much money would have to be deposited today to accumulate a. $10,000 after 6 years if the investment earns 5%/year compounded annually. b. $6,500 after 4 years if the investment earns 8...
-
How much money can be withdrawn at the end of the investment period if a. $1,000 is invested at 8 percent/year compounded annually for 10 years? b. $5,000 is invested at 11 percent/year compounded...
-
What will be the amount accumulated by each of the following present investments? a. $3,000 invested for 7 years at 14 percent compounded annually b. $1,600 invested for 17 years at 12% compounded...
Study smarter with the SolutionInn App