Paprika and Permutation
传送门
Paprika loves permutations. She has an array a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an. She wants to make the array a permutation of integers 1 1 1 to n n n.
In order to achieve this goal, she can perform operations on the array. In each operation she can choose two integers i i i ( 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n) and x x x ( x > 0 x > 0 x>0), then perform a i : = a i m o d x a_i := a_i \bmod x ai:=aimodx (that is, replace a i a_i ai by the remainder of a i a_i ai divided by x x x). In different operations, the chosen i i i and x x x can be different.
Determine the minimum number of operations needed to make the array a permutation of integers 1 1 1 to n n n. If it is impossible, output − 1 -1 −1.
A permutation is an array consisting of n n n distinct integers from 1 1 1 to n n n in arbitrary order. For example, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] [2,3,1,5,4] is a permutation, but [ 1 , 2 , 2 ] [1,2,2] [1,2,2] is not a permutation ( 2 2 2 appears twice in the array) and [ 1 , 3 , 4 ] [1,3,4] [1,3,4] is also not a permutation ( n = 3 n=3 n=3 but there is 4 4 4 in the array).
Input
Each test contains multiple test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1≤t≤104) — the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer n n n ( 1 ≤ n ≤ 1 0 5 1 \le n \le 10^5 1≤n

最低0.47元/天 解锁文章
223

被折叠的 条评论
为什么被折叠?



