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
34
35
#include <stdio.h>
#include <string.h>

int main() {
    char in[20];
    int i, m1 = 1;
    unsigned long long int r = 1, dprev = 1, rprev = 1;
    scanf("%s", in);
    r = (dprev = in[strlen(in)-1]-48) + 1;
    m1 = (dprev % 2 == 1 ? 0 : 1);
//    printf("%llu\n", r);

    for(i = strlen(in) - 2; i >= 0; --i) {
        int d = in[i]-48;
        if (d != 1) {
            m1 = (d % 2 == 1 ? 0 : m1);
            rprev = r;
            r = r*(d+1);
        } else {
            m1 = (dprev == 1 ? 0 : m1);
            unsigned long long int r9 = (9-dprev)*rprev;
            rprev = r;
            r = r*(d+1);
            r += r9;
        }
        dprev = d;
//        printf("d = %d   r = %llu\n", in[i]-48, r);
    }

//    printf("\n    OK! %s %d, %d \n", in, strlen(in), in[0]);
//    printf("m1 = %d\n", m1);
    printf("%llu", r); // - m1

    return 0;
}