From c043df9b44615963cd820112875eb9cdf46f36c4 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Tue, 16 Jun 2020 19:21:49 -0400 Subject: [PATCH] Updated for performance --- .../mattrixwv/ProjectEuler/Problems/Problem16.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java index fe45ef6..eff03b1 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem16.java @@ -1,7 +1,7 @@ //ProjectEuler/Java/Problem16.java //Matthew Ellison // Created: 03-04-19 -//Modified: 03-28-19 +//Modified: 06-16-20 //What is the sum of the digits of the number 2^1000? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses /* @@ -28,9 +28,9 @@ import java.math.BigInteger; public class Problem16 extends Problem{ //The number that is going to be raised to a power - private static final Integer NUM_TO_POWER = 2; + private static final int NUM_TO_POWER = 2; //The power that the number is going to be raised to - private static final Integer POWER = 1000; + private static final int POWER = 1000; public Problem16(){ super("What is the sum of the digits of the number 2^1000?"); @@ -38,13 +38,13 @@ public class Problem16 extends Problem{ public void solve(){ //Setup the other variables BigInteger num = new BigInteger("0"); //The number to be calculated - Integer sumOfElements = 0; //The sum of all digits in the number + int sumOfElements = 0; //The sum of all digits in the number //Start the timer timer.start(); //Get the number - num = BigInteger.valueOf(NUM_TO_POWER.longValue()).pow(POWER); + num = BigInteger.valueOf(NUM_TO_POWER).pow(POWER); //Get a string of the number String numString = num.toString(); @@ -65,5 +65,5 @@ public class Problem16 extends Problem{ /* Results: 2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 The sum of the elements is 1366 -It took 411.699 microseconds to solve this problem. +It took 133.800 microseconds to solve this problem. */