Suppose is an array of length , where all the entries are from the set . For any positive integers , consider the following pseudocode.
DOSOMETHING (c, a, n) z ← 1 for i ← 0 to k-1 do z ← z² mod n if c[i]=1 then z ← (z × a) mod n return z
If , then the output of DOSOMETHING(c, a, n) is _______.
View worked solution
Answer: 0
We can trace the execution of the algorithm step-by-step with the initial value , , and :
- Iteration ():
First, .
Since , . - Iteration ():
First, .
Since , the condition is false, so remains . - Iteration ():
First, .
Since , . - Iteration ():
First, .
Since , .
At the end of the loop, the function returns .
Free practice · Your answers on this page are not saved.
