Escanor's Pride

0

0 votes
Medium
Problem

"Praise the Sun"

We all are aware of Escanor's power and his pride in it. Escanor is also a proud programmer (Wow that's New). To break his pride, Zeldris, Son of the demon king posed a challenge. Zeldris knows what type of questions escanor is weak with (hmm, Who decided that?). Help Escanor solve the question.

Zeldris has given a set of digits R, This set can have digits from 1 to 9

Zeldris wants Escanor to guess the number of positive integers that can be constructed (using the digits of R) that are less than or equal to N. Escanor can use the digits as many times as he wishes.

INPUT FORMAT:
The first line contains 'T' = no. of test cases.
Each Test Case contain 2 lines

First Line - two integers N and K separated by space, as described in the problem statement.

Second Line - Set R of K digits

OUTPUT FORMAT:
For each testcase, print a single integer representing the number of positive integers less than or equal to N.

CONTRAINTS:
1 <= T <= 105
0 <= N <= 109
1 <= K <= 9

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

The 20 numbers that can be written are: 1, 3, 5, 7, 11, 13, 15, 17, 31, 33, 35, 37, 51, 53, 55, 57, 71, 73, 75, 77.

Editor Image

?