Distinct Powers
Consider all integer combinations of a^b for 2 <= a <= 100 and 2 <= b <= 100. How many distinct terms are in the sequence?
Problem Statement
This archive keeps the full statement, math, and original media on the page.
Consider all integer combinations of $a^b$ for $2 \le a \le 5$ and $2 \le b \le 5$: $$ \begin{matrix} 2^2=4, & 2^3=8, & 2^4=16, & 2^5=32\\ 3^2=9, & 3^3=27, & 3^4=81, & 3^5=243\\ 4^2=16, & 4^3=64, & 4^4=256, & 4^5=1024\\ 5^2=25, & 5^3=125, & 5^4=625, & 5^5=3125 \end{matrix} $$
If they are then placed in numerical order, with any repeats removed, we get the following sequence of $15$ distinct terms: $$4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125.$$
How many distinct terms are in the sequence generated by $a^b$ for $2 \le a \le 100$ and $2 \le b \le 100$?
Problem 29: Distinct Powers
Mathematical Development
Definition 1 (Primitive Base). An integer is a primitive base if there do not exist integers and such that . Equivalently, is primitive if it is not a perfect power.
Definition 2 (Canonical Representation). For any integer , the canonical representation is the unique pair where is a primitive base and is an integer such that . Uniqueness follows from the fundamental theorem of arithmetic.
Proof of Uniqueness. Suppose with primitive. Write and in terms of prime factorizations. Then for all . If , then is constant and equals for all , implying . Since is primitive, and , a contradiction.
Theorem 1 (Collision Criterion). Two pairs and satisfy if and only if and share the same primitive base , say and , and .
Proof. () If and with , then .
() Suppose . Let and be canonical. Then . By uniqueness of the canonical representation for the value , we must have and .
Definition 3 (Base Group). For a primitive base , define the base group as the set of all values , and let .
Theorem 2 (Reduction to Exponent Counting). The number of distinct terms in equals
where is the set of distinct effective exponents.
Proof. By Theorem 1, is uniquely determined by its primitive base and effective exponent . Two terms from different base groups are always distinct (different primitive bases). Within a base group, two terms collide iff they share the same effective exponent. Hence the count of distinct terms from base is , and the total is the sum over all primitive bases.
Lemma 1 (Primitive Bases with ). The primitive bases with at least two powers in (i.e., ) are:
| Powers in | ||
|---|---|---|
| 2 | 2, 4, 8, 16, 32, 64 | 6 |
| 3 | 3, 9, 27, 81 | 4 |
| 5 | 5, 25 | 2 |
| 6 | 6, 36 | 2 |
| 7 | 7, 49 | 2 |
| 10 | 10, 100 | 2 |
All other primitive bases satisfy , so their base group contributes exactly distinct terms (the values , all distinct).
Lemma 2 (Exponent Set for ). For , . Thus .
Proof. The set has 99 elements and has 99 elements. Their intersection is , which has 49 elements. By inclusion-exclusion, .
Theorem 3 (Answer). The number of distinct terms is .
Proof. Computed by summing over all primitive bases with . For bases with , each contributes 99. For the six bases with , we compute by explicit enumeration of the exponent sets. The total is verified by direct computation (e.g., using arbitrary-precision arithmetic to store all in a set).
Editorial
We keep two equivalent viewpoints. The direct method enumerates every pair with and inserts into a set, while the canonical method rewrites each base as with primitive base and records the exponent products grouped by . This is sufficient because two powers are equal exactly when they share the same canonical base and exponent.
Pseudocode
Algorithm: Distinct Powers by Direct Enumeration
Require: Positive integers A ≥ 2 and B ≥ 2.
Ensure: The cardinality of {a^b : 2 ≤ a ≤ A, 2 ≤ b ≤ B}.
1: Initialize an empty set S.
2: For each base a in {2, 3, ..., A} do:
3: For each exponent b in {2, 3, ..., B}, insert a^b into S.
4: Return |S|.
Algorithm: Distinct Powers by Canonical Exponents
Require: Positive integers A ≥ 2 and B ≥ 2.
Ensure: The cardinality of {a^b : 2 ≤ a ≤ A, 2 ≤ b ≤ B}.
1: Initialize a map from primitive bases to sets of canonical exponents.
2: For each base a in {2, 3, ..., A}, write a uniquely as c^p with primitive base c.
3: For each exponent b in {2, 3, ..., B}, insert p · b into the exponent set attached to c.
4: Return the total size of all exponent sets.
Complexity Analysis
Proposition (Method 1). Using arbitrary-precision integers, the algorithm runs in time and space, where and is the bit-length of the largest value .
Proof. There are pairs. Each exponentiation produces a number with bits, and hashing/comparing such a number takes time. The set stores at most entries, each of size .
Proposition (Method 2). Using canonical representations, the algorithm runs in time and space, with all arithmetic on -bit integers.
Proof. Computing the canonical representation of each takes time. The double loop inserts entries (each an integer ) into sets keyed by primitive base. Total insertions: .
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// Canonical representation: for each a, find primitive base c and power p
// such that a = c^p. Then a^b = c^(p*b).
vector<pair<int,int>> canon(101); // canon[a] = (base, power)
for (int a = 2; a <= 100; a++) {
canon[a] = {a, 1};
for (int c = 2; c * c <= a; c++) {
int val = c, k = 1;
while (val < a) { val *= c; k++; }
if (val == a) {
auto [base, base_k] = canon[c];
canon[a] = {base, base_k * k};
break;
}
}
}
map<int, set<int>> exponents;
for (int a = 2; a <= 100; a++) {
auto [base, k] = canon[a];
for (int b = 2; b <= 100; b++)
exponents[base].insert(k * b);
}
int total = 0;
for (auto& [base, s] : exponents)
total += s.size();
cout << total << endl;
return 0;
}
def solve():
print(len({a**b for a in range(2, 101) for b in range(2, 101)}))
if __name__ == "__main__":
solve()