Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e6 + 5;
- const int mod = 2020;
- int dp[N];
- int binpow(int a, int n) {
- if (n == 0) return 1;
- if (n % 2 == 1) {
- int b = binpow(a, n - 1);
- return (b * a) % mod;
- } else {
- int b = binpow(a, n / 2);
- return (b * b) % mod;
- }
- }
- int main(){
- int n;
- cin >> n;
- dp[1] = 9;
- for (int i = 2; i <= n; i++) {
- dp[i] = (dp[i - 1] * 10 + dp[i - 2] * 9 * 2) % mod;
- }
- int res = dp[n];
- res -= (binpow(10, n - 1) * 9) % mod;
- if (res < 0) res += mod;
- cout << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement