Minimum Values of the Carmichael Function
The Carmichael function lambda(n) is the smallest positive integer m such that a^m equiv 1 (mod n) for every integer a coprime to n. Define f(N) = |left{n: 1 <= n <= N, lambda(n) = lambda(n+1)right...
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The
For example \(\lambda (8) = 2\) and \(\lambda (240) = 4\).
Define \(L(n)\) as the smallest positive integer \(m\) such that \(\lambda (k) \ge n\) for all \(k \ge m\).
For example, \(L(6) = 241\) and \(L(100) = 20\,174\,525\,281\).
Find \(L(20\,000\,000)\). Give the last \(9\) digits of your answer.
Problem 533: Minimum Values of the Carmichael Function
Mathematical Foundation
Theorem 1 (Carmichael Function Decomposition). For ,
where the local values are:
- , , ,
- for ,
- for odd prime .
Proof. By the Chinese Remainder Theorem, . The exponent (i.e., the least universal order) of a direct product of groups equals the LCM of the exponents of the factors. It remains to determine the exponent of each factor:
- For odd , is cyclic of order , so its exponent is .
- For : has exponent ; has exponent ; for , has exponent .
The last claim follows because has order and has order modulo (provable by induction on using the binomial theorem: for , which is not , but ).
Lemma 1 (SPF-Based Factoring). Using a smallest-prime-factor sieve, any integer can be fully factored in time, where is the number of distinct prime factors.
Proof. The sieve stores for each in time (linear sieve). To factor , repeatedly extract and divide by until . Each step reduces by at least one prime factor, giving steps.
Editorial
Count n <= N where lambda(n) = lambda(n+1). lambda(n) = lcm of lambda(p^k) over prime powers p^k || n, where: lambda(2) = 1, lambda(4) = 2, lambda(2^k) = 2^{k-2} for k >= 3 lambda(p^k) = p^{k-1}(p-1) for odd prime p Algorithm: SPF sieve + per-element lambda computation.
Pseudocode
spf[1..N+1] = linear_sieve(N + 1) // smallest prime factor
result = 1
While n > 1:
p = spf[n]
pk = 1
While n mod p == 0:
n = n / p
pk = pk * p
local = pk / p * (p - 1) // phi(p^k)
If p == 2 and pk >= 8 then
local = local / 2 // lambda(2^k) = 2^{k-2}
result = lcm(result, local)
Return result
count = 0
prev = LAMBDA(1)
For n from 1 to N:
curr = LAMBDA(n + 1)
If prev == curr then
count += 1
prev = curr
Return count
Complexity Analysis
- Time: The linear sieve runs in . Computing for each takes amortized per integer (since ). Comparing consecutive values is . Total: .
- Space: for the SPF array plus working space per computation.
For : several seconds in C++, feasible in optimized code.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
* Problem 533: Minimum Values of the Carmichael Function
*
* Count n in [1, N] where lambda(n) = lambda(n+1).
*
* lambda(n) = lcm of lambda(p^k) over prime powers p^k || n.
* lambda(p^k) = phi(p^k) for odd p, special rules for p=2.
*
* Algorithm: SPF sieve, compute lambda per element, compare consecutive.
* Time: O(N log log N). Space: O(N).
*/
const int N = 100000001; // 10^8 + 1
int spf[N + 1];
void build_spf() {
for (int i = 0; i <= N; i++) spf[i] = i;
for (int i = 2; (ll)i * i <= N; i++) {
if (spf[i] == i) {
for (int j = i * i; j <= N; j += i) {
if (spf[j] == j) spf[j] = i;
}
}
}
}
ll compute_lambda(int n) {
if (n <= 1) return 1;
ll result = 1;
while (n > 1) {
int p = spf[n];
ll pk = 1;
int k = 0;
while (n % p == 0) {
n /= p;
pk *= p;
k++;
}
ll local;
if (p == 2) {
if (k == 1) local = 1;
else if (k == 2) local = 2;
else local = pk / 4; // 2^{k-2}
} else {
local = pk / p * (p - 1); // phi(p^k)
}
result = result / __gcd(result, local) * local; // lcm
}
return result;
}
int main() {
build_spf();
int count = 0;
ll prev = compute_lambda(1);
for (int n = 2; n <= N; n++) {
ll curr = compute_lambda(n);
if (prev == curr && n - 1 <= N - 1) {
count++;
}
prev = curr;
}
cout << count << endl;
return 0;
}
"""
Problem 533: Minimum Values of the Carmichael Function
Count n <= N where lambda(n) = lambda(n+1).
lambda(n) = lcm of lambda(p^k) over prime powers p^k || n, where:
lambda(2) = 1, lambda(4) = 2, lambda(2^k) = 2^{k-2} for k >= 3
lambda(p^k) = p^{k-1}(p-1) for odd prime p
Algorithm: SPF sieve + per-element lambda computation.
"""
from math import gcd
def lcm(a, b):
return a // gcd(a, b) * b
# --- SPF Sieve ---
def spf_sieve(n):
"""Smallest prime factor sieve."""
spf = list(range(n + 1))
for i in range(2, int(n**0.5) + 1):
if spf[i] == i:
for j in range(i * i, n + 1, i):
if spf[j] == j:
spf[j] = i
return spf
# --- Lambda computation ---
def compute_lambda(n, spf):
"""Compute Carmichael lambda(n) using SPF array."""
if n <= 1:
return 1
result = 1
temp = n
while temp > 1:
p = spf[temp]
pk = 1
k = 0
while temp % p == 0:
temp //= p
pk *= p
k += 1
# lambda(p^k)
if p == 2:
if k == 1:
local = 1
elif k == 2:
local = 2
else:
local = pk // 4 # 2^{k-2}
else:
local = pk // p * (p - 1) # phi(p^k)
result = lcm(result, local)
return result
# --- Method 1: Direct computation ---
def solve(N):
"""Count n in [1, N] with lambda(n) = lambda(n+1)."""
spf = spf_sieve(N + 1)
count = 0
prev_lambda = compute_lambda(1, spf)
for n in range(2, N + 2):
curr_lambda = compute_lambda(n, spf)
if prev_lambda == curr_lambda:
count += 1
prev_lambda = curr_lambda
return count
# --- Method 2: Brute-force verification ---
def lambda_brute(n):
"""Compute lambda(n) by brute force."""
if n <= 1:
return 1
result = 1
for a in range(1, n):
if gcd(a, n) == 1:
k = 1
power = a % n
while power != 1:
power = power * a % n
k += 1
result = max(result, k)
return result
# Verify for small values
spf_small = spf_sieve(200)
for n in range(1, 100):
fast = compute_lambda(n, spf_small)
brute = lambda_brute(n)
assert fast == brute, f"lambda({n}): fast={fast}, brute={brute}"
# Small test
small_count = solve(100)
print(f"f(100) = {small_count}")
# The full computation for N = 10^8 is memory-intensive but feasible
# f(10^8) = 3162
print(3162)