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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char const *argv[]) {
  unsigned long long int in, tmp, result=1;
  int dbl[20], last=0, dblCount = 0;

  for (int i=0; i<20; i++) {
    dbl[i]=0;
  }

  cin >> in;
  tmp = in;
  do {
    if (tmp%10 == 1 && last > 0 && last < 9) {
      dbl[dblCount++] = 10 + last;
    }
    last = tmp%10;
    result *= last+1;
    tmp /= 10;
  } while (tmp >= 10);
  
  if (tmp == 1 && last < 9) {
    dbl[dblCount++] = 10 + last;
  }
  result *= tmp+1;
  tmp = result;
  bool last11 = false;

  for (int i=1; i<pow(2, dblCount); i++) {
    int tmpI = i;
    last11 = false;
    for (int j=dblCount-1; j>=0; j--) {
      int twoPow = pow(2, j);
      if (tmpI >= twoPow && !last11) {
        tmpI /= twoPow;
        result += (tmp / (2 * (1 + dbl[j]%10))) * (19-dbl[j]);
        last11 = dbl[j] == 11;
      } else if (last11) {
        last11 = false;
        if (j==0 && i==pow(2, dblCount)-1) {
          result -= (tmp / (2 * (1 + dbl[j+1]%10))) * (19-dbl[j+1]);
        }
      }
    }
  }

  cout << result;
  return 0;
}