Project Euler Lab - Problem 652

#652 - Distinct Values of a Proto-logarithmic Function

● ResearchOfficial difficulty: 79%Naive enumeration is infeasible; requires a mathematical reductionTier D - conceptual / notebook executionNot viewed
↖ Euler Lab

Consider the values of \(\log_2(8)\), \(\log_4(64)\) and \(\log_3(27)\). All three are equal to \(3\).

Generally, the function \(f(m,n)=\log_m(n)\) over integers \(m,n \ge 2\) has the property that
\(f(m_1,n_1)=f(m_2,n_2)\) if

  1. \(\, m_1=a^e, n_1=a^f, m_2=b^e,n_2=b^f \,\) for some integers \(a,b,e,f \, \,\) or
  2. \( \, m_1=a^e, n_1=b^e, m_2=a^f,n_2=b^f \,\) for some integers \(a,b,e,f \,\)

We call a function \(g(m,n)\) over integers \(m,n \ge 2\) proto-logarithmic if

  • \(\quad \, \, \, \, g(m_1,n_1)=g(m_2,n_2)\) if any integers \(a,b,e,f\) fulfilling 1. or 2. can be found
  • and \(\, g(m_1,n_1) \ne g(m_2,n_2)\) if no integers \(a,b,e,f\) fulfilling 1. or 2. can be found.

Let \(D(N)\) be the number of distinct values that any proto-logarithmic function \(g(m,n)\) attains over \(2\le m, n\le N\).
For example, \(D(5)=13\), \(D(10)=69\), \(D(100)=9607\) and \(D(10000)=99959605\).

Find \(D(10^{18})\), and give the last \(9\) digits as answer.


Note: According to the four exponentials conjecture the function \(\log_m(n)\) is proto-logarithmic.
While this conjecture is yet unproven in general, \(\log_m(n)\) can be used to calculate \(D(N)\) for small values of \(N\).

This problem is taken from Project Euler, Problem 652.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=652. Published Saturday, 19th January 2019, 10:00 pm. Solved by 199 members at time of mirroring.

Why this is useful

Optimization. The transferable skill is replacing infeasible enumeration with a mathematical reduction - the core move in calibration and large-scale computation (Phases 10, 13).

We classify relevance honestly - not every Euler problem is a trading application.

Prerequisites

Lessons that prepare you:
17.1 Python for Quants: NumPy, pandas, and Vectorization · 19.14 Computational Complexity, Feasibility Estimation, and Proving Algorithms Correct · 19.4 Exact Arithmetic: Big Integers, Rationals, and Floating-Point Traps

Recommended stepping-stone problems: #466 · #676 · #442

Concepts: brute-force-reduction

Likely techniques: big-integer hashing

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier D - conceptual / notebook execution
Too heavy for browser Pyodide at original scale: the browser is used for planning, small cases and reasoning; full scale runs in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.