Self Powers
The series 1^1 + 2^2 + 3^3 +... + 10^10 = 10,405,071,317. Find the last ten digits of the series 1^1 + 2^2 + 3^3 +... + 1000^1000.
Problem Statement
This archive keeps the full statement, math, and original media on the page.
The series, \(1^1 + 2^2 + 3^3 + \cdots + 10^{10} = 10405071317\).
Find the last ten digits of the series, \(1^1 + 2^2 + 3^3 + \cdots + 1000^{1000}\).
Problem 48: Self Powers
Mathematical Development
Formal Development
Definition 1. The self-power sum of order is . We seek .
Theorem 1 (Compatibility of modular reduction with ring operations). Let be an integer. The map defined by is a ring homomorphism. In particular, for all :
- ,
- .
Proof. Write , with .
(1) , so .
(2) , so .
Corollary 1. .
Proof. Apply the additive property of Theorem 1 inductively over summands.
Theorem 2 (Binary exponentiation). For integers , , and modulus , the value can be computed in modular multiplications.
Proof. Write in binary: where and . Then:
The sequence is computed by repeated squaring:
requiring one modular multiplication per step ( total). An accumulator is initialized to and multiplied by whenever (at most multiplications). The total number of modular multiplications is at most .
When fits in a machine word, each modular multiplication is , giving overall time.
Lemma 1 (Last ten digits). The last ten digits of a non-negative integer are given by .
Proof. In decimal representation, with . The remainder consists of the last ten digits (padded with leading zeros if ).
Theorem 3. The last ten digits of are .
Proof. Set . By Corollary 1:
Each term is computed via binary exponentiation (Theorem 2) using modular multiplications. Since , all intermediate products fit in 64-bit integers, so each multiplication is .
The computation yields .
Verification. For : , whose last 10 digits are . Our modular computation agrees: .
Editorial
We carry out the entire computation modulo , since only the last ten digits are required. For each from to , the term is computed by modular exponentiation and added to an accumulator that is itself reduced modulo after every step. The final residue is exactly the desired suffix of the full sum.
Pseudocode
Algorithm: Last Ten Digits of the Self-power Sum
Require: The modulus M ← 10^10.
Ensure: The final ten digits of ∑_{k=1}^1000 k^k.
1: Initialize total ← 0.
2: For each k in {1, 2, ..., 1000}, compute t ← k^k mod M by modular exponentiation.
3: Update total ← (total + t) mod M.
4: Return total.
Complexity Analysis
Proposition (Time complexity). The algorithm runs in time, where .
Proof. The outer loop executes iterations. In iteration , the call to MODPOW performs modular multiplications, each costing (since fits in 64 bits). The total work is:
For , this is approximately operations.
Proposition (Space complexity). The algorithm uses auxiliary space.
Proof. Only the accumulator total and the local variables of MODPOW (result, base, exp) are maintained. No arrays or dynamic data structures are required.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long base, long long exp, long long mod) {
long long result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1)
result = ((__int128)result * base) % mod;
base = ((__int128)base * base) % mod;
exp >>= 1;
}
return result;
}
int main() {
const long long MOD = 10000000000LL;
long long answer = 0;
for (int k = 1; k <= 1000; k++)
answer = (answer + modpow(k, k, MOD)) % MOD;
printf("%010lld\n", answer);
return 0;
}
"""
Problem 48: Self Powers
Find the last ten digits of 1^1 + 2^2 + 3^3 + ... + 1000^1000.
Uses modular exponentiation with M = 10^10.
"""
def solve():
M = 10**10
total = 0
for k in range(1, 1001):
total = (total + pow(k, k, M)) % M
return total
answer = solve()
assert answer == 9110846700
print(answer)