#P1611. 循环的数字

循环的数字

Description

Have you ever felt bored with a TV program because you kept seeing the same thing repeat over and over? Well, I do not really care about TV shows, but sometimes numbers also cycle like that.

Assume two distinct positive integers (n,m)(n, m) are cyclic if and only if you can move some digits from the end of nn to the front, without changing the order of the moved digits, so that the whole number becomes mm. For example, (12345,34512)(12345, 34512) is a cyclic pair because you can move the trailing 345345 of 1234512345 in front of 1212 to get 3451234512. Note that to be a cyclic pair, nn and mm must have the same number of digits. Neither nn nor mm has leading zeros.

Now given positive integers AA and BB, guaranteed to have the same number of digits and no leading zeros, count the number of cyclic pairs (n,m)(n, m) such that AnmBA \leq n \le m \leq B.

Input Format

This problem has 10 test points. Each input file contains 1 line. The first line contains two space-separated positive integers A and B.

Output Format

Each output file should contain a single integer x, representing the number of cyclic pairs (n,m)(n, m) such that AnmBA \leq n \le m \leq B.

1111 2222
287

Hint

1A,B2×1061\le A,B \leq 2\times 10^6.

Translated by ChatGPT 5