Four functions problem
Let me put together the two comments.
The function $A$ is Euler's totient function, which is often called $\phi$.
The function $B(x)=\sum_{d|n}\phi(d)$ is known to be equal to $B(x)=x$.
Now, observe that $D(x)=\sum_{i=1}^{x}C(B(i))=\sum_{i=1}^{x}C(i)=C(x!)$, where the last equation is because $C$ satisfies $C(a)+C(b)=C(ab)$.
Now, if $p_1&lt;p_2&lt;\ldots&lt;p_k$ are the primes less than or equal to $x$ and $x!=p_1^{a_1}p_2^{a_2}\dotsm p_k^{a_k}$, then $$C(x!)=a_1+a_2+...+a_k$$
We can use Legendre's formula to compute each $a_i$. Note that the formula doesn't need to compute $x!$, but it computes $$a_i=\left\lfloor\frac{x}{p_i}\right\rfloor+\left\lfloor\frac{x}{p_i^2}\right\rfloor+\left\lfloor\frac{x}{p_i^3}\right\rfloor+\ldots$$
where there are actually finitely many summands.
So, an algorithm to compute $D(x)$ can be:

Compute the primes $p_1,p_2,\ldots,p_k$ up to $x$. This can be done using some sieve, like Erathostenes' or Atkin's
Then for each prime evaluate Legendre's formula above, which takes about $\log_{p_i}(x)$ divisions.