CF1759F.All Possible Digits

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A positive number xx of length nn in base pp ( 2p1092 \le p \le 10^9 ) is written on the blackboard. The number xx is given as a sequence a1,a2,,ana_1, a_2, \dots, a_n ( 0ai<p0 \le a_i < p ) — the digits of xx in order from left to right (most significant to least significant).

Dmitry is very fond of all the digits of this number system, so he wants to see each of them at least once.

In one operation, he can:

  • take any number xx written on the board, increase it by 11 , and write the new value x+1x + 1 on the board.

For example, p=5p=5 and x=2345x=234_5 .

  • Initially, the board contains the digits 22 , 33 and 44 ;
  • Dmitry increases the number 2345234_5 by 11 and writes down the number 2405240_5 . On the board there are digits 0,2,3,40, 2, 3, 4 ;
  • Dmitry increases the number 2405240_5 by 11 and writes down the number 2415241_5 . Now the board contains all the digits from 00 to 44 .

Your task is to determine the minimum number of operations required to make all the digits from 00 to p1p-1 appear on the board at least once.

输入格式

The first line of the input contains a single integer tt ( 1t21031 \le t \le 2 \cdot 10^3 ) — the number of test cases. The descriptions of the input test cases follow.

The first line of description of each test case contains two integers nn ( 1n1001 \le n \le 100 ) and pp ( 2p1092 \le p \le 10^9 ) — the length of the number and the base of the number system.

The second line of the description of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai<p0 \le a_i < p ) — digits of xx in number system with base pp

It is guaranteed that the number xx does not contain leading zeros (that is, a1>0a_1>0 ).

输出格式

For each test case print a single integer — the minimum number of operations required for Dmitry to get all the digits on the board from 00 to p1p-1 .

It can be shown that this always requires a finite number of operations.

输入输出样例

  • 输入#1

    11
    2 3
    1 2
    4 2
    1 1 1 1
    6 6
    1 2 3 4 5 0
    5 2
    1 0 1 0 1
    3 10
    1 2 3
    5 1000
    4 1 3 2 5
    3 5
    2 3 4
    4 4
    3 2 3 0
    1 3
    2
    5 5
    1 2 2 2 4
    3 4
    1 0 1

    输出#1

    1
    1
    0
    0
    7
    995
    2
    1
    1
    1
    2
首页