Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * @author Mat
- */
- package problem.pkg48;
- import java.math.BigInteger;
- public class Problem48 {
- public static void main(String[] args) {
- BigInteger total = new BigInteger("1"); // first result 1^1 = 1
- // loop through starting at 2^2 + then 3^3 +... 1000^1000 into total
- for(BigInteger i = BigInteger.valueOf(2);
- i.compareTo(BigInteger.valueOf(1000)) <= 0 ; i = i.add(BigInteger.ONE)){
- total = total.add((i.pow(Integer.parseInt(i.toString()))));
- }
- String s1 = total.toString();
- System.out.println("The answer to the question is: " +
- s1.substring(s1.length()-10));
- }
- }
- /* Output
- * The answer to the question is: 9110846700
- */
Advertisement
Add Comment
Please, Sign In to add comment