Data Structures & AlgorithmsModerateCodeforces Div2 B · modular arithmetic
Problem: What is 2^100 mod 7? Run the code.
Problem: What is 2^100 mod 7? Run the code.
print(pow(2, 100, 7))What is printed?
- A. 1
- B. 4
- C. 2
- D. 3
Correct answer: C. 2
2^3 = 8 ≡ 1 (mod 7), and 100 = 3 * 33 + 1, so 2^100 ≡ 2^1 = 2.
More Coding Interview Problems questions
- Problem: What is the length of the shortest path from node 1 to node 5 in the undirected graph with edges (1,2), (2,3), (1,4), (4,5)…
- Problem: How many connected components does the graph on vertices 0..5 with edges (0,1), (2,3), (4,5), (1,2) have? Run the union-find…
- Problem: Does the undirected graph with edges (0,1), (1,2), (2,0) contain a cycle? Run the union-find check and print 'cycle' or 'no…
- Problem: How many nodes are reachable from 0 in the directed graph with edges 0->1, 1->2, 3->0? Run the DFS code. python g = {0: [1], 1…
- Problem: Why does BFS find shortest paths in an unweighted graph in O(V + E) time?
- Problem: Which data structure supports inserting values, deleting values and answering 'how many stored values are at most x' in O(log n)…