topic:
If the number is A or B, the number is good number. If a good number is a good number, the number is excellent. Give a B and the data length is Len, question: How many excellent numbers are in Len's number
Analysis:
The number of groups that are greater than the upper limit.
We can have I a, and then there will be len-I B.
If a * I + (LEN-I) * B is good, we can select I position from Len position for,Place len-I in B. Therefore, the preceding combination is C (Len, I ).
The answer is sigma (C (Len, k), a * k + (LEN-k) * B is good
As Len is larger than Len, we need to implement regionalization.
C (n, I) = n! /(M! * (N-m )! )
So we can pass through the request (M! * (N-m )! ), And then n! * Inv is the combination number.
Because the subject time limit is still relatively limited, we need to handle the Multiplication
The last time is 46 ms, or faster.
# Include <cstdio> # include <cstring> # include <iostream> using namespace STD; typedef long ll; # define rep (I, n) for (INT I = 0; I <n; I ++) # define rep1 (I, n) for (INT I = 1; I <= N; I ++) # define rd3 (x, y, z) scanf ("% d", & X, & Y, & Z) /****************************/const int mod = 1e9 + 7; const int maxn = 1e6 + 5; int A, B, Len; ll FAC [maxn]; bool OK (INT N) {While (n) {int t = n % 10; if (T! = A & T! = B) Return false; N/= 10;} return true;} ll ext_gcd (ll a, LL B, ll & X, ll & Y) {If (B = 0) {x = 1; y = 0; return a;} ll res = ext_gcd (B, A % B, Y, X ); y-= A/B * X; return res;} ll inv (LL A) {// calculate the reverse yuan ll D, X, Y in the number of bytes during the fair expansion; D = ext_gcd (A, Mod, x, y); If (D = 1) Return (X % mod + mod) % MOD; Return-1 ;} ll C (int n, int m) {// combination number formula: n! /(N-m )! * M!) = N! * Inv (n-m )! * M!) Return FAC [N] * inv (FAC [m] * FAC [n-M] % mod) % MOD;} int main () {# ifndef online_judgefreopen ("sum. in "," r ", stdin); // freopen (" sum. out "," W ", stdout); # endif rd3 (a, B, Len); FAC [0] = 1; rep1 (I, Len) FAC [I] = FAC [I-1] * I % MOD; ll ans = 0; For (INT I = 0; I <= Len; I ++) if (OK (I * A + (LEN-I) * B) ans + = C (Len, I); printf ("% i64d \ n ", ans % mod); Return 0 ;}