All submissions for this problem are available.
How many times does the integer K occur in the sequence obtained by writing out all the natural numbers from 1 to N, without any whitespace in between.
For example, if N = 20, the sequence would look like
In the above sequence, the integer 12 occurs exactly 2 times. Also, the integer 11 appears exactly 2 times. Note that the two occurances of 11 overlap, but should still be counted separately.
The first line of input consists of an integer T - the number of the test cases. Then, T lines, consisting of two integers N and K follow. N and K are separated by a single space.
For every test case, output the number of times that the integer K appears in the string, obtained by writing out the first N natural numbers.
1 ≤ N, K ≤ 1000000 1 ≤ Sum of N over all the test cases ≤ 1000000
5 100 333 97 5 4 5 11 1 10 1
1 20 0 4 2
|Tags||acmkgp13, ad-hoc, easy, string, xcwgf666|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, GO|
Fetching successful submissions