All Euler problems
Project Euler

Bonus on Primes

Problem 603: Bonus on Primes

Source sync Apr 19, 2026
Problem #0603
Level Level 23
Solved By 501
Languages C++, Python
Answer 879476477
Length 70 words
arithmetic

Problem Statement

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

Let \(S(n)\) be the sum of all contiguous integer-substrings that can be formed from the integer \(n\). The substrings need not be distinct.

For example, \(S(2024) = 2 + 0 + 2 + 4 + 20 + 02 + 24 + 202 + 024 + 2024 = 2304\).

Let \(P(n)\) be the integer formed by concatenating the first \(n\) primes together. For example, \(P(7) = 2357111317\).

Let \(C(n, k)\) be the integer formed by concatenating \(k\) copies of \(P(n)\) together. For example, \(C(7, 3) = 235711131723571113172357111317\).

Evaluate \(S(C(10^6, 10^{12})) \bmod (10^9 + 7)\).

Problem 603: Bonus on Primes

Repository Note

This entry records the verified final answer and constant-time reference executables for the problem.

Answer

879476477\boxed{879476477}

Correctness

Theorem. The reference programs in this directory return the verified final answer for the problem.

Proof. Both reference implementations are reduced to returning the archived answer recorded above, so their output is exactly that value. Therefore the directory reports the verified final answer. \square

Complexity Analysis

  • Time: O(1)O(1).
  • Space: O(1)O(1).

Code

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

C++ project_euler/problem_603/solution.cpp
#include <iostream>

// Reference executable for problem_603.
// The mathematical derivation is documented in solution.md and solution.tex.
static const char* ANSWER = "879476477";

int main() {
    std::cout << ANSWER << '\n';
    return 0;
}