T1:
"Data Range"
40% of the data meet a<=105;
another 30% of the data meet n,m<=109 ;| s|,| T|<=10 (| s| = length of s);
100% of data meet n,m<=109 ;| s|,| t|<=106.
The number of occurrences of the match in the Loop section, that is, the LCM (S,t), is first obtained.
Then multiply the number of loops.
is the number of equal character logarithm of the position of D=GCD (s,t) in the s,t.
Can prove.
Prove:
Set S length to l1,t length of L2
If the character of position A in S is the same as the character of position B in T.
If it can be matched within the loop section.
So satisfying exists K1,K2:A+K1*L1=B+K2*L2
We're going to find out now, whether K1,K2 exists, there are several.
Move item: k1*l1-k2*l2=b-a;
Solution conditions are: D=GCD (L1,L2) | (b-a), otherwise k1,k2 does not exist
(B-a the positive and negative pairs of the solution is not insignificant, assuming a positive number)
If there is a solution, set x= (b-a)/D;
So, at the same time divided by D, can have: K1*l1 '-k2*l2 ' =x;
Among them, L1 ', L2 ' coprime.
Then there is, K1*l1 ' =x+k2*l2 '
Available:k1*l1 ' =x mod (L2 ')
And, because X is less than L2 ', if there is a nonnegative integer k1 that conforms to the equation, then there must be a unique nonnegative integer k2
So the equivalent Yu Tongyu equation k1*l1 ' =x mod (L2 ') K1 has several nonnegative integer solutions.
Because of L1 ', L2 ' coprime, there is a k1=x*l1 ' ^ ( -1) mod (L2 ') that is less than L2 '
So, can this K1 add several times to L2 '?
Found
In fact, K1 now has a condition.
Because now it's inside the Loop section, and 0<=a<l1;
and Lcm=l2 ' *L1
So, 0<=k1<l2 ', otherwise it's beyond the LCM
Since L1 ', L2 ' coprime, there is a k1=x*l1 ' ^ ( -1) mod (L2 ')
And K1 cannot be greater than or equal to L2 ', so this K1 has only one.
And now we have proved that
In d=gcd (L1,L2) | ( B-A) , there is an opportunity for A/b match within the loop section.
So we can enumerate the characters char∈a~z
The characters are all two positions in Char B,a about the remainder classification of d.
AI,BI locations with the same remainder must be matched once. Because the difference must be a multiple of d.
So, we can sweep two times s,t to record the position char appears.
You can then multiply the number of identical classes directly.
Finally, multiply the cycle times of the Loop section.
Code:
9.29 Demo Game