All Euler problems
Project Euler

Stealthy Numbers

A positive integer N is stealthy if there exist positive integers a, b, c, d such that a b = c d = N and a + b = c + d + 1. For example, 36 = 4 x 9 = 6 x 6 is stealthy since 4 + 9 = 13 = 6 + 6 + 1....

Source sync Apr 19, 2026
Problem #0757
Level Level 12
Solved By 1,543
Languages C++, Python
Answer 75737353
Length 183 words
brute_forcelinear_algebra

Problem Statement

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

A positive integer \(N\) is stealthy, if there exist positive integers \(a\), \(b\), \(c\), \(d\) such that \(ab = cd = N\) and \(a+b = c+d+1\).

For example, \(36 = 4\times 9 = 6\times 6\) is stealthy.

You are also given that there are 2851 stealthy numbers not exceeding \(10^6\).

How many stealthy numbers are there that don’t exceed \(10^{14}\)?

Problem 757: Stealthy Numbers

Mathematical Analysis

Key Observation: Bipronic Numbers

A stealthy number NN can be written as N=abN = a \cdot b where a+b=c+d+1a + b = c + d + 1 and cd=Nc \cdot d = N.

If we write ab=cda \cdot b = c \cdot d and a+b=c+d+1a + b = c + d + 1, we can use the identity relating factorizations to sums. Consider two factorizations of NN: N=ab=cdN = a \cdot b = c \cdot d with a+b(c+d)=1a + b - (c + d) = 1.

Connection to Pronic Numbers

A pronic (oblong) number is a number of the form n(n+1)n(n+1). The key insight is:

Theorem: A positive integer NN is stealthy if and only if NN can be expressed as N=pqN = p \cdot q where both pp and qq are pronic numbers (i.e., p=x(x+1)p = x(x+1) and q=y(y+1)q = y(y+1) for positive integers x,yx, y).

Proof: If N=x(x+1)y(y+1)N = x(x+1) \cdot y(y+1), set:

  • a=xy(y+1)a = x \cdot y(y+1), b=(x+1)b = (x+1)… more carefully:
  • a=(x+1)(y+1)a = (x+1)(y+1), b=xyb = xy, so ab=xy(x+1)(y+1)=Nab = xy(x+1)(y+1) = N
  • c=x(y+1)c = x(y+1), d=y(x+1)d = y(x+1), so cd=xy(x+1)(y+1)=Ncd = xy(x+1)(y+1) = N
  • a+b=(x+1)(y+1)+xy=xy+x+y+1+xy=2xy+x+y+1a + b = (x+1)(y+1) + xy = xy + x + y + 1 + xy = 2xy + x + y + 1
  • c+d=x(y+1)+y(x+1)=xy+x+xy+y=2xy+x+yc + d = x(y+1) + y(x+1) = xy + x + xy + y = 2xy + x + y
  • Therefore a+b=c+d+1a + b = c + d + 1. QED.

Editorial

Enumerate all products x(x+1)y(y+1)1014x(x+1) \cdot y(y+1) \leq 10^{14} where xyx \leq y, and count distinct values using a hash set or sorted merge approach.

For the upper bound on xx: since x(x+1)x(x+1)1014x(x+1) \cdot x(x+1) \leq 10^{14}, we need x(x+1)107x(x+1) \leq 10^7, giving x3162x \leq \approx 3162.

For each xx, yy ranges from xx to the largest value such that x(x+1)y(y+1)1014x(x+1) \cdot y(y+1) \leq 10^{14}.

Complexity Analysis

  • Time: O(MlogM)O(M \log M) where MM is the total number of products generated (around 10710^7), dominated by sorting/deduplication.
  • Space: O(M)O(M) to store all products.

Answer

75737353\boxed{75737353}

Code

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

C++ project_euler/problem_757/solution.cpp
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long LIMIT = 100000000000000LL; // 10^14
    vector<long long> results;

    // x(x+1) * y(y+1) <= LIMIT, with x <= y
    // x(x+1) <= sqrt(LIMIT) ~ 10^7
    for(long long x = 1; x*(x+1)*(x)*(x+1) <= LIMIT; x++){
        long long px = x * (x + 1);
        for(long long y = x; ; y++){
            long long py = y * (y + 1);
            long long val = px * py;
            if(val > LIMIT) break;
            results.push_back(val);
        }
    }

    sort(results.begin(), results.end());
    long long count = unique(results.begin(), results.end()) - results.begin();

    cout << count << endl;
    return 0;
}