Solution to Project Euler Problem 48: Self powers - The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317. Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
Updated: Sept. 21, 2023 — Training Time: 1 Minute
Overseen by: Archangel Macsika
All Training Resources
Scroll for more menu list
Topic: Project Euler Problem 48: Self powers.
Difficulty: Easy.
Objective: The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
Input: None.
Expected Output: 9110846700.
Sikademy Solution in Java Programming Language
package sikademy;
/**
*
* @author Archangel Macsika
* Copyright (c) Sikademy. All rights reserved
*/
import java.math.BigInteger;
public class SikademyEulerSolution {
public String run() {
BigInteger modulus = BigInteger.TEN.pow(10);
BigInteger sum = BigInteger.ZERO;
for (int i = 1; i <= 1000; i++)
sum = sum.add(BigInteger.valueOf(i).modPow(BigInteger.valueOf(i), modulus));
return sum.mod(modulus).toString();
}
public static void main(String[] args) {
SikademyEulerSolution solution = new SikademyEulerSolution();
System.out.println(solution.run());
}
}
Sikademy Solution in Python Programming Language
#
# @author Archangel Macsika
# Copyright (c) Sikademy. All rights reserved.
#
def compute():
MOD = 10**10
ans = sum(pow(i, i, MOD) for i in range(1, 1001)) % MOD
return str(ans)
if __name__ == "__main__":
print(compute())