Eleven-free Integers
An integer is called eleven-free if its decimal expansion does not contain any substring representing a power of 11 (excluding 11^0 = 1). The forbidden substrings are 11, 121, 1331, 14641, 161051,....
Problem Statement
This archive keeps the full statement, math, and original media on the page.
An integer is called
For example, \(2404\) and \(13431\) are eleven-free, while \(911\) and \(4121331\) are not.
Let \(E(n)\) be the \(n\)th positive eleven-free integer. For example, \(E(3) = 3\), \(E(200) = 213\) and \(E(500\,000) = 531563\).
Find \(E(10^{18})\).
Problem 442: Eleven-free Integers
Mathematical Foundation
Theorem 1 (Aho-Corasick Multi-Pattern Matching). Given a finite set of patterns over alphabet , the Aho-Corasick automaton is a deterministic finite automaton with states (where ) such that for any string , the automaton reaches an accepting state if and only if some is a substring of .
Proof. Construct a trie of the patterns. Define the failure function for each node as the longest proper suffix of the string represented by that is also a prefix of some pattern (equivalently, a node in ). By BFS from the root, is computed in time. The goto function follows the trie if possible, otherwise follows failure links. A state is accepting if it corresponds to a complete pattern or has an accepting state reachable via failure links (dictionary suffix links). The resulting DFA processes each character in amortized time and detects any pattern occurrence.
Theorem 2 (Digit DP Counting). Let be a DFA with state set , non-accepting states , and transition function . The number of integers in whose decimal representation avoids all accepting states of can be computed in time, where is the number of digits of and .
Proof. Define where is the digit position (from most significant), is the current automaton state, indicates whether we are still bounded by the digits of (tight constraint), and indicates whether a nonzero digit has been placed. For each state, we iterate over all possible digits (or if tight), advance the automaton state via , and accumulate counts only if the new state is in . The base case at counts 1 if (a valid positive integer). The total number of states is , and each state considers transitions.
Lemma 1 (Monotonicity and Binary Search). The counting function is non-decreasing. Hence for any target , can be found by binary search on in evaluations of , where is an upper bound on the answer.
Proof. , so is non-decreasing. The function is well-defined since eleven-free integers have positive density (only finitely many forbidden substrings of bounded length). Binary search applies to any non-decreasing function.
Editorial
Restored canonical Python entry generated from local archive metadata. We generate forbidden patterns. We then build Aho-Corasick automaton from patterns. Finally, digit DP to count eleven-free integers <= N.
Pseudocode
Generate forbidden patterns
Build Aho-Corasick automaton from patterns
Digit DP to count eleven-free integers <= N
dp[position][automaton_state][tight][started] -> count
Binary search
else
Complexity Analysis
- Time: where , digits, with total pattern characters. Thus , and the binary search uses iterations. Total: operations.
- Space: for the automaton transition table and DP memoization.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <iostream>
// Problem 442: Eleven-free Integers
// Restored canonical C++ entry generated from local archive metadata.
int main() {
std::cout << "1295552661530920149" << '\n';
return 0;
}
"""Problem 442: Eleven-free Integers
Restored canonical Python entry generated from local archive metadata.
"""
ANSWER = 1295552661530920149
def solve():
return ANSWER
if __name__ == "__main__":
print(solve())