text: size(); int bsize = B.size(); for (int i = asize; i <= 501; ++i) { A = '0' + A; } for (int i = bsize; i <= 501; ++i) { B= '0' + B; } Mod ans = 0; for (int i = 0; i < 10; ++i) { bool amore = i >= (A[501] - '0'); bool bless = i <= (B[501] - '0'); dp[0][i][0][amore][bless][i%M][0]+=1; dp[0][i][1][amore][bless][i%M][0]+=1; dp[0][i][0][amore][bless][i%M][1] += 1; } for (int keta = 1; keta <= 501; ++keta) { for (int prenum = 0; prenum < 10; ++prenum) { for (int upping = 0; upping < 2; ++upping) { for (int amore = 0; amore < 2; ++amore) { for (int bless = 0; bless< 2; ++bless) { for (int bai = 0; bai < M; ++bai) { for (int death = 0; death < 2; ++death) { if (dp[keta - 1][prenum][upping][amore][bless][bai][death]) { for (int nextnum = 0; nextnum < 10; ++nextnum) { if (death){ if (nextnum) { continue; } } else { if (upping) { if (nextnum <= prenum)continue; } else { if (nextnum >= prenum)continue; } } bool nextamore, nextbless; if (nextnum >(A[501 - keta] - '0')) { nextamore = true; } else if (nextnum == (A[501 - keta] - '0')) { nextamore = amore; } else { nextamore = false; } if (nextnum > (B[501 - keta] - '0')) { nextbless = false; } else if (nextnum == (B[501 - keta] - '0')) { nextbless = bless; } else { nextbless = true; } int nextbai = bai +powmod(10, keta,M)*nextnum; nextbai %= M; assert(nextbai < mod); if (keta == 1 && nextnum == 1 && (!upping) == 1 && nextamore == 1 && nextbless == 1 && nextbai == 0) { int c = 0; c++; } dp[keta][nextnum][!upping][nextamore][nextbless][nextbai][death] += dp[keta - 1][prenum][upping][amore][bless][bai][death]; /*if (nextnum == 0 && keta == 3 && !nextbai&&death) { cout << nextnum << " " << prenum << endl; cout << dp[keta - 1][prenum][upping][amore][bless][bai][death] << endl;; }*/ if (!death&&nextnum) { dp[keta][nextnum][!