All Euler problems
Project Euler

Investigating the Behaviour of a Recursively Defined Sequence

Given the function: f(x) = floor(2^(30.403243784 - x^2)) * 10^(-9) and the sequence u_0 = -1, u_(n+1) = f(u_n), find floor((u_n + u_(n+1)) x 10^9) for sufficiently large n (written as x.xxxxxxxxx).

Source sync Apr 19, 2026
Problem #0197
Level Level 06
Solved By 5,540
Languages C++, Python
Answer 1.710637717
Length 286 words
geometrysequenceanalytic_math

Problem Statement

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

Given is the function $f(x) = \lfloor 2^{30.403243784 - x^2}\rfloor \times 10^{-9}$ ($\lfloor \, \rfloor$ is the floor-function),

the sequence $u_n$ is defined by $u_0 = -1$ and $u_{n + 1} = f(u_n)$.

Find $u_n + u_{n + 1}$ for $n = 10^{12}$.

Give your answer with $9$ digits after the decimal point.

Problem 197: Investigating the Behaviour of a Recursively Defined Sequence

Mathematical Foundation

Theorem 1. (2-Cycle Convergence.) The sequence {un}\{u_n\} converges to a 2-cycle: there exist constants a,bR>0a, b \in \mathbb{R}_{>0} with aba \neq b such that f(a)=bf(a) = b and f(b)=af(b) = a. Moreover, for all sufficiently large nn:

u2na,u2n+1b.u_{2n} \to a, \quad u_{2n+1} \to b.

Proof. Define g=ffg = f \circ f. We show gg is a contraction on a suitable interval IaI \ni a.

Step 1: Existence of a 2-cycle. The function ff maps R\mathbb{R} into [0,C][0, C] for some constant C>0C > 0 (since 230.403...x2109\lfloor 2^{30.403... - x^2} \rfloor \cdot 10^{-9} is bounded). Thus f([0,C])[0,C]f([0, C]) \subseteq [0, C], so gg maps [0,C][0, C] to itself. By the Brouwer fixed-point theorem, gg has a fixed point aa in [0,C][0, C], giving g(a)=ag(a) = a, i.e., f(f(a))=af(f(a)) = a. Setting b=f(a)b = f(a), we have f(b)=af(b) = a.

Step 2: aba \neq b (not a fixed point). A fixed point of ff would require 230.403...a2=a×109\lfloor 2^{30.403... - a^2} \rfloor = a \times 10^9. Numerical evaluation shows no such solution exists: the equation 230.403...a2a×1092^{30.403... - a^2} \approx a \times 10^9 has solutions near a0.68a \approx 0.68 and a1.03a \approx 1.03, but the floor function prevents either from being exact. Instead, ff maps one neighbourhood to the other.

Step 3: Contraction. The derivative of gg at aa is g(a)=f(b)f(a)g'(a) = f'(b) \cdot f'(a). Ignoring the floor function (which is locally constant almost everywhere), f(x)=2xln2230.403...x2109f'(x) = -2x \ln 2 \cdot 2^{30.403... - x^2} \cdot 10^{-9}. Numerical evaluation gives f(a)0.7|f'(a)| \approx 0.7 and f(b)0.5|f'(b)| \approx 0.5, so g(a)0.35<1|g'(a)| \approx 0.35 < 1. By the contraction mapping principle (Banach fixed-point theorem), gn(u0)ag^n(u_0) \to a exponentially. \square

Theorem 2. (Stability of the Sum.) For all sufficiently large nn, the sum un+un+1u_n + u_{n+1} is independent of the parity of nn:

un+un+1=a+bfor all large n.u_n + u_{n+1} = a + b \quad \text{for all large } n.

Proof. For even n=2kn = 2k: u2k+u2k+1a+bu_{2k} + u_{2k+1} \to a + b. For odd n=2k+1n = 2k+1: u2k+1+u2k+2b+a=a+bu_{2k+1} + u_{2k+2} \to b + a = a + b. \square

Lemma 1. (Convergence Rate.) The convergence is exponentially fast. After 100\sim 100 iterations, un+un+1u_n + u_{n+1} is stable to the full precision of IEEE 754 double-precision arithmetic (15\sim 15 decimal digits).

Proof. The error after nn iterations of gg satisfies gn(u0)ag(a)nu0a|g^n(u_0) - a| \leq |g'(a)|^n \cdot |u_0 - a|. With g(a)0.35|g'(a)| \approx 0.35, after 100 iterations the error is bounded by 0.3550u0a<10220.35^{50} \cdot |u_0 - a| < 10^{-22}, well below double precision. \square

Editorial

f(x) = floor(2^(30.403243784 - x^2)) * 1e-9 u_0 = -1, u_{n+1} = f(u_n) Converges to 2-cycle. Find floor((u_n + u_{n+1}) * 10^9). We iterate over i from 1 to 1000.

Pseudocode

for i from 1 to 1000
Now u_n and u_{n+1} are converged

Complexity Analysis

  • Time: O(N)O(N) where N1000N \approx 1000 iterations. Each iteration requires one floating-point exponentiation (O(1)O(1) with hardware support).
  • Space: O(1)O(1) — only two floating-point variables.

Answer

1.710637717\boxed{1.710637717}

Code

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

C++ project_euler/problem_197/solution.cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
    double u = -1.0;
    for (int i = 0; i < 1000; i++)
        u = floor(pow(2.0, 30.403243784 - u * u)) * 1e-9;
    double u_n = u;
    double u_n1 = floor(pow(2.0, 30.403243784 - u * u)) * 1e-9;
    long long ans = (long long)floor((u_n + u_n1) * 1e9);
    assert(ans == 1710637717LL);
    cout << fixed << setprecision(9) << ans / 1e9 << endl;
    return 0;
}