Question
Suppose is an array of length , where all the entries are from the set . For any positive integers and , consider the following pseudocode:
DOSOMETHING (c, a, n)
z = 1
for i = 0 to k - 1
do z = z^2 mod n
if c[i] == 1
then z = (z * a) mod n
return z
If and , then the output of DOSOMETHING(c, a, n) is _____.
Official answer and solution
- Official answer
- 0
- From
- Official GATE 2015 answer key
Solution
Trace the loop iterations of the modular exponentiation algorithm.
Given inputs:
- Array so
- Base
- Modulus
Trace execution:
- Initial:
- : .
Since , . - : .
Since , remains 4. - : .
Since , . - : .
Since , .
The function returns .
0
Overlooking that 4^2 = 16 is divisible by 8 (16 mod 8 = 0), collapsing all subsequent multiplications to 0.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2015 Computer Science and Information Technology (CS) Session 3
- Question
- 59 of 65, printed as CS Q.49
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.