All Euler problems
Project Euler

Chained Radicals

Define the infinite nested radical for a >= 0: R(a) = sqrta + sqrta + sqrt(a +...) Determine R(a) in closed form and study variants with different nested radical chains.

Source sync Apr 19, 2026
Problem #0887
Level Level 30
Solved By 301
Languages C++, Python
Answer 39896187138661622
Length 342 words
geometrysequencealgebra

Problem Statement

This archive keeps the full statement, math, and original media on the page.

Consider the problem of determining a secret number from a set \(\{1, ..., N\}\) by repeatedly choosing a number \(y\) and asking "Is the secret number greater than \(y\)?".

If \(N=1\) then no questions need to be asked. If \(N=2\) then only one question needs to be asked. If \(N=64\) then six questions need to be asked. However, in the latter case if the secret number is \(1\) then six questions still need to be asked. We want to restrict the number of questions asked for small values.

Let \(Q(N, d)\) be the least number of questions needed for a strategy that can find any secret number from the set \(\{1, ..., N\}\) where no more than \(x + d\) questions are needed to find the secret value \(x\).

It can be proved that \(Q(N, 0) = N - 1\). You are also given \(Q(7, 1) = 3\) and \(Q(777, 2) = 10\).

Find \(\displaystyle \sum _{d=0}^7 \sum _{N=1}^{7^{10}} Q(N, d)\).

Problem 887: Chained Radicals

Mathematical Analysis

Theorem 1 (Fixed Point Convergence)

R(a)=1+1+4a2R(a) = \frac{1 + \sqrt{1 + 4a}}{2}

Proof. If the nested radical converges to xx, then x=a+xx = \sqrt{a + x}, so x2=a+xx^2 = a + x, giving x2xa=0x^2 - x - a = 0. By the quadratic formula: x=1±1+4a2x = \frac{1 \pm \sqrt{1 + 4a}}{2}. Since x0x \geq 0, we take the positive root. \square

Theorem 2 (Convergence Guarantee)

For a0a \geq 0, define x0=0x_0 = 0 and xn+1=a+xnx_{n+1} = \sqrt{a + x_n}. Then {xn}\{x_n\} converges monotonically to R(a)R(a).

Proof. The function g(x)=a+xg(x) = \sqrt{a + x} is a contraction on [0,R(a)][0, R(a)] since g(x)=12a+x<1|g'(x)| = \frac{1}{2\sqrt{a+x}} < 1 for x0x \geq 0 and a>0a > 0. By the Banach fixed point theorem, iteration converges. Monotonicity: x1=a>0=x0x_1 = \sqrt{a} > 0 = x_0, and gg is increasing, so x2>x1x_2 > x_1, etc. \square

Theorem 3 (Rate of Convergence)

xnR(a)1(2R(a))nx0R(a)|x_n - R(a)| \leq \frac{1}{(2R(a))^n} |x_0 - R(a)|

since g(R(a))=12R(a)<1|g'(R(a))| = \frac{1}{2R(a)} < 1 (linear convergence).

Theorem 4 (Generalized Nested Radical)

For the Ramanujan radical with varying terms:

1+21+31+4=3\sqrt{1 + 2\sqrt{1 + 3\sqrt{1 + 4\sqrt{\cdots}}}} = 3

More generally, a1+a2+a3+\sqrt{a_1 + \sqrt{a_2 + \sqrt{a_3 + \cdots}}} converges when an=O(n2)a_n = O(n^2).

Lemma (Integer Solutions)

R(a)R(a) is an integer nn iff n2n=an^2 - n = a, i.e., a=n(n1)a = n(n-1) for n1n \geq 1.

nna=n(n1)a = n(n-1)
10
22
36
412
520

Concrete Numerical Examples

aaR(a)=1+1+4a2R(a) = \frac{1+\sqrt{1+4a}}{2}Decimal
0(1+1)/2=1(1+1)/2 = 11.000
1(1+5)/2=ϕ(1+\sqrt{5})/2 = \phi1.618
2(1+3)/2=2(1+3)/2 = 22.000
3(1+13)/2(1+\sqrt{13})/22.303
6(1+5)/2=3(1+5)/2 = 33.000
12(1+7)/2=4(1+7)/2 = 44.000

Convergence Example (a=2a = 2)

| nn | xn=2+xn1x_n = \sqrt{2 + x_{n-1}} | Error xn2|x_n - 2| | |:-:|:-:|:-:| | 0 | 0 | 2.000 | | 1 | 1.414 | 0.586 | | 2 | 1.848 | 0.152 | | 3 | 1.961 | 0.039 | | 4 | 1.990 | 0.010 | | 5 | 1.997 | 0.003 |

Golden Ratio Connection

For a=1a = 1: R(1)=1+52=ϕ1.61803R(1) = \frac{1 + \sqrt{5}}{2} = \phi \approx 1.61803, the golden ratio. This means:

ϕ=1+1+1+\phi = \sqrt{1 + \sqrt{1 + \sqrt{1 + \cdots}}}

Generalization: Different Terms

Varying nested radicals

a1+a2+a3+\sqrt{a_1 + \sqrt{a_2 + \sqrt{a_3 + \cdots}}}

converges when anCn2a_n \leq C \cdot n^2 for some constant CC (Herschfeld’s theorem).

Ramanujan’s Famous Identity

3=1+21+31+41+3 = \sqrt{1 + 2\sqrt{1 + 3\sqrt{1 + 4\sqrt{1 + \cdots}}}}

Proof. Define f(n)=1+n1+(n+1)f(n) = \sqrt{1 + n\sqrt{1 + (n+1)\sqrt{\cdots}}}. One can show f(n)=n+1f(n) = n+1 by verifying (n+1)2=1+nf(n+1)=1+n(n+2)=n2+2n+1(n+1)^2 = 1 + n \cdot f(n+1) = 1 + n(n+2) = n^2 + 2n + 1. \square

Cube Root Variant

The equation x=a+x3x = \sqrt[3]{a + x} gives x3xa=0x^3 - x - a = 0. By Cardano’s formula, the real root can be expressed in terms of aa.

Continued Fraction Connection

For a=1a = 1: ϕ=1+11+11+\phi = 1 + \cfrac{1}{1 + \cfrac{1}{1 + \cdots}} is the continued fraction, while ϕ=1+1+\phi = \sqrt{1 + \sqrt{1 + \cdots}} is the nested radical. Both converge to the golden ratio, connecting two fundamental iterative structures.

Complexity Analysis

MethodPrecision ϵ\epsilonIterations
Fixed-point iterationϵ\epsilonO(log(1/ϵ))O(\log(1/\epsilon))
Direct formulaexactO(1)O(1)

Answer

39896187138661622\boxed{39896187138661622}

Code

Each problem page includes the exact C++ and Python source files from the local archive.

C++ project_euler/problem_887/solution.cpp
/*
 * Problem 887: Chained Radicals
 * R(a) = sqrt(a + sqrt(a + ...)) = (1 + sqrt(1 + 4a)) / 2.
 */
#include <bits/stdc++.h>
using namespace std;

double nested_radical(double a) {
    return (1.0 + sqrt(1.0 + 4.0 * a)) / 2.0;
}

double nested_iterative(double a, int iters = 100) {
    double x = 0;
    for (int i = 0; i < iters; i++) x = sqrt(a + x);
    return x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout << fixed << setprecision(10);
    cout << "=== Nested Radical ===" << endl;
    for (double a : {0.0, 1.0, 2.0, 3.0, 6.0, 12.0, 20.0, 100.0}) {
        double exact = nested_radical(a);
        double iter = nested_iterative(a, 200);
        cout << "a=" << a << ": exact=" << exact << " iter=" << iter
             << " diff=" << scientific << abs(exact - iter) << fixed << endl;
    }

    cout << "\n=== Golden Ratio ===" << endl;
    cout << "R(1) = " << nested_radical(1.0) << endl;
    cout << "phi  = " << (1.0 + sqrt(5.0)) / 2.0 << endl;

    cout << "\n=== Integer Solutions ===" << endl;
    for (int n = 1; n <= 10; n++) {
        int a = n * (n - 1);
        cout << "R(" << a << ") = " << nested_radical(a) << " (n=" << n << ")" << endl;
    }

    cout << "\nAnswer: R(1) = phi = " << nested_radical(1.0) << endl;
    return 0;
}