ProgrammingVery hardTCS NQT · Accenture
The procedure below finds how many integers x with 1 <= x <= 200 satisfy x^2 mod 13 == 1. What is printed?
The procedure below finds how many integers x with 1 <= x <= 200 satisfy x^2 mod 13 == 1. What is printed?
count = 0
for x = 1 to 200
if (x * x) mod 13 == 1 then count = count + 1
end for
Print count- A. 16
- B. 15
- C. 31
- D. 30
Correct answer: C. 31
The residues with x^2 = 1 mod 13 are x = 1 and x = 12 (mod 13). Up to 200 there are 15 full cycles (30 values) plus x = 196, giving 31. Testing only x = 1 mod 13 gives 16, restricting to odd x gives 15, and stopping at 195 gives 30.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The procedure below computes the value of the sum 1^2 + 2^2 + ... + 10^2 using the formula n(n+1)(2n+1)/6 for n = 10, and then the loop…
- Count the integers n with 1 <= n <= 1000 that are divisible by 7 but NOT divisible by 11. The procedure below does this with one loop…
- Count the integers n with 1 <= n <= 500 that are divisible by 4 or by 6. The procedure below uses a single loop. What is printed? count =…
- Find the gcd of the array [84, 126, 210, 462] by folding the Euclidean gcd across the elements, starting from 0. The procedure below runs…
- The number of trailing zeros of 1000! equals the power of 5 in 1000!, which is the sum of floor(1000 / 5^k) for k = 1, 2, 3, ... The…
- The least common multiple of the integers 1 through 10 is computed by folding lcm(a, b) = a b div gcd(a, b) from L = 1. The procedure…