All Euler problems
Project Euler

Dirichlet Series Evaluation

Define D(s) = sum_(n=1)^N (mu(n))/(n^s) where mu is the Mobius function. Find floor(D(2) * 10^12) for N = 10^7.

Source sync Apr 19, 2026
Problem #0943
Level Level 39
Solved By 102
Languages C++, Python
Answer 1038733707
Length 175 words
number_theorylinear_algebrageometry

Problem Statement

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

Given two unequal positive integers \(a\) and \(b\), we define a self-describing sequence consisting of alternating runs of \(a\)s and \(b\)s. The first element is \(a\) and the sequence of run lengths is the original sequence.

For \(a=2, b=3\), the sequence is: \[2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...\] The sequence begins with two \(2\)s and two \(3\)s, then three \(2\)s and three \(3\)s, so the run lengths \(2, 2, 3, 3, ...\) are given by the original sequence.

Let \(T(a, b, N)\) be the sum of the first \(N\) elements of the sequence. You are given \(T(2,3,10) = 25\), \(T(4,2,10^4) = 30004\), \(T(5,8,10^6) = 6499871\).

Find \(\sum T(a, b, 22332223332233)\) for \(2 \le a \le 223\), \(2 \le b \le 223\) and \(a \neq b\). Give your answer modulo \(2233222333\).

Problem 943: Dirichlet Series Evaluation

Mathematical Analysis

The Mobius Function

Definition. μ(n)=(1)k\mu(n) = (-1)^k if nn is a product of kk distinct primes, μ(n)=0\mu(n) = 0 if nn has a squared prime factor, and μ(1)=1\mu(1) = 1.

Connection to the Riemann Zeta Function

Theorem. n=1μ(n)ns=1ζ(s)\sum_{n=1}^{\infty} \frac{\mu(n)}{n^s} = \frac{1}{\zeta(s)} for Re(s)>1\text{Re}(s) > 1.

For s=2s = 2: 1ζ(2)=6π20.607927...\frac{1}{\zeta(2)} = \frac{6}{\pi^2} \approx 0.607927...

Truncated Sum

D(2)=n=1Nμ(n)n26π2n>Nμ(n)n2D(2) = \sum_{n=1}^{N} \frac{\mu(n)}{n^2} \approx \frac{6}{\pi^2} - \sum_{n>N} \frac{\mu(n)}{n^2}.

The tail is O(1/N)O(1/N), so for N=107N = 10^7, D(2)6/π2D(2) \approx 6/\pi^2 to about 7 decimal places.

Editorial

Compute D(s) = sum_{n=1}^{N} mu(n) / n^s for s = 2, which converges to 6/pi^2 (the reciprocal of the Riemann zeta function at s=2). The Mobius function mu(n) is: mu(1) = 1 mu(n) = (-1)^k if n is a product of k distinct primes mu(n) = 0 if n has a squared prime factor The target is floor(D(2) * 10^12) for large N. Results:. We sieve μ(n)\mu(n) for nNn \leq N using a linear sieve. Finally, compute μ(n)/n2\sum \mu(n)/n^2 using floating-point or exact rational arithmetic.

Pseudocode

Sieve $\mu(n)$ for $n \leq N$ using a linear sieve
Compute $\sum \mu(n)/n^2$ using floating-point or exact rational arithmetic
Floor the result times $10^{12}$

The Mobius Sieve

Initialize μ(1)=1\mu(1) = 1. For each prime pp: for multiples mm of pp, multiply μ(m)\mu(m) by 1-1. For multiples of p2p^2, set μ(m)=0\mu(m) = 0.

Proof of Correctness

  1. Mobius sieve: Standard.
  2. Sum: Floating-point with sufficient precision, or use integer arithmetic.

Complexity Analysis

  • Sieve: O(NloglogN)O(N \log \log N).
  • Sum: O(N)O(N).

Answer

1038733707\boxed{1038733707}

Code

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

C++ project_euler/problem_943/solution.cpp
#include <bits/stdc++.h>
using namespace std;
int main(){
    const int N=1000000;
    vector<int> mu(N+1,0);
    mu[1]=1;
    vector<bool> is_p(N+1,true);
    vector<int> primes;
    for(int i=2;i<=N;i++){
        if(is_p[i]){primes.push_back(i);mu[i]=-1;}
        for(int p:primes){
            if((long long)i*p>N) break;
            is_p[i*p]=false;
            if(i%p==0){mu[i*p]=0;break;}
            else mu[i*p]=-mu[i];
        }
    }
    double D=0;
    for(int n=1;n<=N;n++) D+=mu[n]/(double)n/(double)n;
    cout<<fixed<<setprecision(12)<<D<<endl;
    return 0;
}