Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
How many integers x in [0, 20] satisfy x^3 ≡ x (mod 7)?
- A. 10
- B. 9
- C. 7
- D. 13
Correct answer: B. 9
Fermat's little theorem gives x^7 ≡ x, so x^3 ≡ x holds on the residues that are 0 or x^2 ≡ 1 mod 7, i.e. 0, 1 and 6 modulo 7.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- The 3-row by 4-column matrix is filled row by row with 1 to 12. What is the 7th element when the matrix is read in clockwise spiral order…
- A sliding window of size 3 moves over the array [5, 1, 4, 2, 8, 7, 6]. For each window take its maximum and then take the minimum of those…
- What is the number of distinct values of a[i] XOR a[j] over all pairs i < j of the array [1, 2, 3, 4]?
- How many palindromic substrings does the string aabbaa contain (counted by position)?
- What is the number of distinct subsequences (including the empty one) of the string abab?
- Starting at value 1, apply the operations x -> 2x, then x -> x + 3, alternating (double, add 3, double, add 3, ...), for 6 operations in…