1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>

using namespace std;
int MAX_VAL = 20;

int main(){
    long long int number;
    scanf("%lld", &number);
    long long int result [MAX_VAL];
    long long int vectorized [MAX_VAL];


    long long int backup = number;
    vectorized[0] = 0;
    for (int idx = 1; idx < MAX_VAL; ++idx) {
        vectorized[idx] = backup % 10;
        backup /= 10;
    }

    result[0] = 1;
    result[1] = (number % 10) + 1;

    for (int idx = 2; idx < MAX_VAL; ++idx) {
        if (vectorized[idx] == 1 && vectorized[idx-1] != 9) {
            result[idx] = 2 * result[idx-1] + (9-vectorized[idx-1])*result[idx-2];
        } else {
            result[idx] = (vectorized[idx] + 1) * result[idx-1];
        }
    }

    printf("%lld\n", result[MAX_VAL-1]);
    return 0;
}