Perfect Imperfections 2

 An array of integers is called good if all its elements are perfect squares.

You are given an array

of

integers. In one move, you can do the following:

  • Pick a subset of indices of the array, say
where
  • Next, pick an integer
  • Finally, multiply the value at each chosen index by
  • , i.e, set to for each

    Find the minimum number of moves required to make the array good.

    Note: The value of

    is fixed for a given move, but can vary between moves.

    Input Format

    • The first line of input contains an integer
    , denoting the number of test cases. The description of
  • test cases follows.
  • Each test case contains two lines of input.
  • The first line of each test case contains
  • , the size of the array.
  • The second line contains
  • space-separated integers
    • .

    Output Format

    For each testcase, output in a single line the minimum number of moves required to make the array good.

    Constraints

  • The sum of
  • across all testcases won't exceed
    • .

    Subtasks

    Subtask #1 (100 points): Original constraints

    Sample Input 1

    5
    3
    15 2 4
    4
    15 14 4 9
    3
    10 3 6
    2
    4 9
    2
    2 8
    

    Sample Output 1

    2
    2
    3
    0
    1
    

    Explanation

    Test case

    : One possible sequence of moves is:

    • Multiply the first element by
  • Multiply the second element by

    The array is now

    , which is good.

    Test case

    : One possible sequence of moves is:

    • Multiply the first and third elements by
  • Multiply the second and third elements by
  • Multiply the first element by

    The array is now

    , which is good.

    Test case

    : The array is already good, since , so no moves need to be made.
    Previous
    Next Post »