#P9897. Enclosed Areas Recursion Function

    ID: 23042 Type: Default 1000ms 256MiB

Enclosed Areas Recursion Function

Enclosed Areas Recursion Function

Consider a function \(f(x)\) that calculates the total number of enclosed areas in the digits of \(x\). The number of enclosed areas for each digit is defined as follows:

  • \(0\) has 1 enclosed area.
  • \(1\) has 0 enclosed areas.
  • \(2\) has 0 enclosed areas.
  • \(3\) has 0 enclosed areas.
  • \(4\) has 1 enclosed area.
  • \(5\) has 0 enclosed areas.
  • \(6\) has 1 enclosed area.
  • \(7\) has 0 enclosed areas.
  • \(8\) has 2 enclosed areas.
  • \(9\) has 1 enclosed area.

We now define a recursive function \(g\) as follows:

\[ \begin{cases} g^0(x) = x, \\ g^k(x) = f\bigl(g^{k-1}(x)\bigr) \quad\text{for } k \ge 1. \end{cases} \]

Given two integers \(x\) and \(k\), compute \(g^k(x)\).

inputFormat

The input consists of a single line containing two integers \(x\) and \(k\), separated by a space.

outputFormat

Output the value of \(g^k(x)\).

sample

1234 2
0