orazma

a.cpp

May 4th, 2026
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define f first
  3. #define s second
  4. #define pb push_back
  5. #define mp make_pair
  6. #define ll long long
  7.  
  8. #define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  9.  
  10. using namespace std;
  11. const int INF = 1e9 + 1;
  12. const int MOD = 1e9 + 7;
  13. const int MAXN = 6e4 + 10;
  14. const int L = 20;
  15.  
  16. int dp[MAXN][10][128];
  17. int mods[20000];
  18.  
  19. void solve(){
  20.     int n, x;
  21.     cin >> n >> x;
  22.  
  23.     for (int i = 0; i <= 9; i++){
  24.         dp[1][i][i % x]++;
  25.     }
  26.  
  27.     for (int i = 0; i < 20000; i++){
  28.         mods[i] = i % x;
  29.     }
  30.  
  31.     for (int i = 2; i <= n; i++){
  32.         for (int j = 0; j <= 9; j++){
  33.             for (int k = 0; k <= 9; k++){
  34.                 if (k == j) continue;
  35.                 for (int mod = 0; mod < x; mod++){
  36.                     int mod2 = mods[mod * 10 + j];
  37.                     dp[i][j][mod2] += dp[i - 1][k][mod];
  38.                     if (dp[i][j][mod2] >= MOD){
  39.                         dp[i][j][mod2] -= MOD;
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     }
  45.     int ans = 0;
  46.     for (int i = 0; i <= 9; i++){
  47.         ans += dp[n][i][0];
  48.         if (ans >= MOD){
  49.             ans -= MOD;
  50.         }
  51.     }
  52.     cout << ans << "\n";
  53. }
  54.  
  55. int main() {
  56.  
  57.     IOS;
  58.     int t = 1;
  59.     //cin >> t;
  60.     while(t--){
  61.         solve();
  62.     }
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment