Question: Problem 1. You are given a positive integer n (that is stored in a register of the CPU). Design an algorithm to determine whether n
Problem 1. You are given a positive integer n (that is stored in a register of the CPU). Design an algorithm to determine whether n is an even number. Your algorithm should have a cost no more than 10.
Problem 2. You are given two positive integers n and m (stored in two registers of the CPU). Design an algorithm to calculate n mod m. Your algorithm should have a cost no more than 10. Note: n mod m is the remainder of n divided by m. For example, 10 mod 2 = 0 and 13 mod 3 = 1.
Problem 3. You are given a positive integer n (that is stored in a register of the CPU). Design an algorithm to determine whether n is a prime number. Your algorithm should have a cost no more than 100 n. Note that calculating n is not an atomic operation.
Problem 4. You are given two positive integers n and m (stored in two registers of the CPU), where n is a power of 2. Design an algorithm to calculate mn . Your algorithm should have a cost no more than 100 log2 n.
Problem 1. You are given a positive integer n (that is stored in a register of the CPU). Design an algorithm to determine whether n is an even number. Your algorithm should have a cost no more than 10. Problem 2. You are given two positive integers n and m (stored in two registers of the CPU). Design an algorithm to calculate nmodm. Your algorithm should have a cost no more than 10 . Note: nmodm is the "remainder" of n divided by m. For example, 10mod2=0 and 13 mod3=1. Problem 3. You are given a positive integer n (that is stored in a register of the CPU). Design an algorithm to determine whether n is a prime number. Your algorithm should have a cost no more than 100n. Note that calculating n is not an atomic operation. Problem 4. You are given two positive integers n and m (stored in two registers of the CPU), where n is a power of 2 . Design an algorithm to calculate mn. Your algorithm should have a cost no more than 100log2n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
