# The Devil is in the Details

**Calculus**Level 4

Consider the recurrence relation \( \large f_{n+1} (x) = x^{ f_n (x) } \), for non-negative integers \(n\) with \(f_0 (x) = 1 \).

\[ \large\displaystyle \lim_{x \to 1} \frac { f_{666} (x) - 1}{x^{666} - 1} \]

Let the limit above equals to \(\frac AB\) for coprime positive integers \(A \) and \(B\).

Denote \(D\) as the absolute difference between the smallest and largest prime factors of \(A+B\).

What is the value of \(1 + 2 + 3 + \ldots + (D^2 - 1) + D^2 \)?