Mock CCC 25 S4 - Perfect Numbers
Theodore has recently become obsessed with "perfect" numbers. The definition of a "perfect" number is that if we take a number \(x\) cast it as a string, if we can find a substring of the number so that if the number of distinct substrings of such substring is even then the number is perfect.
Ex: \(12113\) is a "perfect" number because we can pick a substring \(1211\) and that has \(8\) distinct substrings: \(1\), \(2\), \(11\), \(12\), \(21\), \(121\), \(211\), \(1211\).
Theodore wants to know the answer to the following question. Looking at all the numbers from \(L\) to \(R\) inclusive, how many of them are "perfect"?
Constraints
Subtask 1 [3/15]
\(0 \le L, R \le 10 ^ 3\)
Subtask 3 [12/15]
\(0 \le L,R \le 10 ^ {9}\)
Input Specification
The first and only line will contain two space seperated integers, \(L\) and \(R\).
Output Specification
Output one integer, the number of numbers from \(L\) to \(R\) inclusive that are "perfect".
Sample Input
1 11
Sample Output
1
Explanation for Sample Output
Only \(11\) is a perfect number as it has \(2\) distinct substrings.
Comments