Data Structures & AlgorithmsVery hardCodeforces Div2 B · ICPC regional
How many index pairs i < j make a[i] times a[j] a perfect square, for the array [2, 8, 18, 5, 12, 9, 50, 25, 32]?
- A. 10
- B. 22
- C. 31
- D. 11
Correct answer: D. 11
A product is a square exactly when the two square-free parts are equal. Parts: 2, 2, 2, 5, 3, 1, 2, 1, 2, so C(5,2) + C(2,2) = 11. Missing the (9, 25) pair gives 10, counting ordered pairs gives 22, and also pairing each element with itself gives 31.
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
- Keys 10, 22, 31, 4, 15, 28, 17, 88, 59 are inserted in this order into an open-addressing table of size 11 with h(k) = k mod 11 and linear…
- A table of size 11 uses double hashing with h1(k) = k mod 11 and h2(k) = 1 + (k mod 9), probe position (h1 + ih2) mod 11. Keys 5, 16, 27…
- What is the value of the prefix-function (KMP failure function) at the last position of the string aabaaab?
- What is the sum of the Z-function values Z[i] for i = 1 to n-1 of the string aaabaaab (Z[i] is the length of the longest common prefix of…
- How many palindromic substrings (counted by position, so repeated letters at different positions count separately) does the string…
- What is the minimum number of characters that must be inserted anywhere in the string abcbd to make it a palindrome?