#P16752. [GKS 2020 #B] Bus Routes

[GKS 2020 #B] Bus Routes

Problem Description

Bucket is planning to make a very long journey across the countryside by bus. Her journey consists of NN bus routes, numbered from 1 to NN in the order she must take them. The buses themselves are very fast, but do not run often. The ii-th bus route only runs every XiX_i days.

More specifically, she can only take the ii-th bus on day XiX_i, 2Xi2X_i, 3Xi3X_i and so on. Since the buses are very fast, she can take multiple buses on the same day.

Bucket must finish her journey by day DD, but she would like to start the journey as late as possible. What is the latest day she could take the first bus, and still finish her journey by day DD?

It is guaranteed that it is possible for Bucket to finish her journey by day DD.

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case begins with a line containing the two integers NN and DD. Then, another line follows containing NN integers, the ii-th one is XiX_i.

Output Format

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the latest day she could take the first bus, and still finish her journey by day DD.

3
3 10
3 7 2
4 100
11 10 5 50
1 1
1
Case #1: 6
Case #2: 99
Case #3: 1

Hint

In Sample Case #1, there are N=3N = 3 bus routes and Bucket must arrive by day D=10D = 10. She could:

  • Take the 1st bus on day 66 (X1=3X_1 = 3),
  • Take the 2nd bus on day 77 (X2=7X_2 = 7) and
  • Take the 3rd bus on day 88 (X3=2X_3 = 2).

In Sample Case #2, there are N=4N = 4 bus routes and Bucket must arrive by day D=100D = 100. She could:

  • Take the 1st bus on day 9999 (X1=11X_1 = 11),
  • Take the 2nd bus on day 100100 (X2=10X_2 = 10),
  • Take the 3rd bus on day 100100 (X3=5X_3 = 5) and
  • Take the 4th bus on day 100100 (X4=50X_4 = 50),

In Sample Case #3, there is N=1N = 1 bus route and Bucket must arrive by day D=1D = 1. She could:

  • Take the 1st bus on day 11 (X1=1X_1 = 1).

Limits

1T1001 \le T \le 100.

1XiD1 \le X_i \le D.

1N10001 \le N \le 1000.

It is guaranteed that it is possible for Bucket to finish her journey by day DD.

Test Set 1

1D1001 \le D \le 100.

Test Set 2

1D10121 \le D \le 10^{12}.