CF1617C Paprika and Permutation 题解 贪心

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 1in) 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 1t104) — 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 1n

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值