Advertisement
Mirbek

B (ODS)

Jan 28th, 2022
637
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 5;
  6. const int mod = 2020;
  7.  
  8. int dp[N];
  9.  
  10. int binpow(int a, int n) {
  11.     if (n == 0) return 1;
  12.     if (n % 2 == 1) {
  13.         int b = binpow(a, n - 1);
  14.         return (b * a) % mod;
  15.     } else {
  16.         int b = binpow(a, n / 2);
  17.         return (b * b) % mod;
  18.     }
  19. }
  20.  
  21. int main(){
  22.     int n;
  23.     cin >> n;
  24.  
  25.     dp[1] = 9;
  26.  
  27.     for (int i = 2; i <= n; i++) {
  28.         dp[i] = (dp[i - 1] * 10 + dp[i - 2] * 9 * 2) % mod;
  29.     }
  30.  
  31.     int res = dp[n];
  32.     res -= (binpow(10, n - 1) * 9) % mod;
  33.     if (res < 0) res += mod;
  34.  
  35.     cout << res << endl;
  36. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement