Company: Uidai_2_Jan
Difficulty: medium
K-special numbers K-special numbers Statement You are given a range [L, R] and an integer k . An integer A consisting of n digits a 1 a 2 ...a n in decimal representation without any leading zeros is called a K-special number if, for all digit positions i (from 1 to n ), the following condition holds true: (a i mod k) ≡ (i mod k) Task Determine the number of K-special numbers in the range [L, R] , inclusive. Notes The problem uses 1-based indexing for digit positions. For example, in the number 123, a 1 =1 , a 2 =2 , and a 3 =3 . Example 1 Input: k = 2, L = 8, R = 15 Output: 4 Explanation: The numbers in the range [8, 15] are {8, 9, 10, 11, 12, 13, 14, 15}. The K-special numbers are {9, 10, 12, 14}. For example, let's check the number 14: - For the 1st digit (a 1 =1): (1 mod 2) ≡ (1 mod 2) → 1 ≡ 1. (True) - For the 2nd digit (a 2 =4): (4 mod 2) ≡ (2 mod 2) → 0 ≡ 0. (True) Since the condition holds for all digits, 14 is a K-special number. The tot