mirror of
https://bitbucket.org/Mattrixwv/projecteulerjava.git
synced 2025-12-07 01:23:56 -05:00
Updated for performance
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
//ProjectEuler/Java/Problem29.java
|
//ProjectEulerJava/src/main/java/mattrixwv/ProjectEuler/Problems/Problem29.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 10-09-19
|
// Created: 10-09-19
|
||||||
//Modified: 10-09-19
|
//Modified: 06-17-20
|
||||||
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/JavaClasses
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2019 Matthew Ellison
|
Copyright (C) 2020 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -29,13 +29,13 @@ import java.math.BigInteger;
|
|||||||
|
|
||||||
public class Problem29 extends Problem{
|
public class Problem29 extends Problem{
|
||||||
//The lowest possible value for a
|
//The lowest possible value for a
|
||||||
private static final Integer BOTTOM_A = 2;
|
private static final int BOTTOM_A = 2;
|
||||||
//The highest possible value for a
|
//The highest possible value for a
|
||||||
private static final Integer TOP_A = 100;
|
private static final int TOP_A = 100;
|
||||||
//The lowest possible value for b
|
//The lowest possible value for b
|
||||||
private static final Integer BOTTOM_B = 2;
|
private static final int BOTTOM_B = 2;
|
||||||
//The highest possible value for b
|
//The highest possible value for b
|
||||||
private static final Integer TOP_B = 100;
|
private static final int TOP_B = 100;
|
||||||
//Holds all unique values generated
|
//Holds all unique values generated
|
||||||
private ArrayList<BigInteger> unique;
|
private ArrayList<BigInteger> unique;
|
||||||
|
|
||||||
@@ -46,13 +46,13 @@ public class Problem29 extends Problem{
|
|||||||
//Setup the variables
|
//Setup the variables
|
||||||
unique = new ArrayList<BigInteger>();
|
unique = new ArrayList<BigInteger>();
|
||||||
|
|
||||||
//Start the time
|
//Start the timer
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
//Start with the first A and move towards the top
|
//Start with the first A and move towards the top
|
||||||
for(Integer currentA = BOTTOM_A;currentA <= TOP_A;++currentA){
|
for(int currentA = BOTTOM_A;currentA <= TOP_A;++currentA){
|
||||||
//Start with the first B and move towards the top
|
//Start with the first B and move towards the top
|
||||||
for(Integer currentB = BOTTOM_B;currentB <= TOP_B;++currentB){
|
for(int currentB = BOTTOM_B;currentB <= TOP_B;++currentB){
|
||||||
//Get the new number
|
//Get the new number
|
||||||
BigInteger currentNum = BigInteger.valueOf(currentA).pow(currentB);
|
BigInteger currentNum = BigInteger.valueOf(currentA).pow(currentB);
|
||||||
//If the current number is not in the array add it
|
//If the current number is not in the array add it
|
||||||
@@ -72,5 +72,5 @@ public class Problem29 extends Problem{
|
|||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
||||||
It took 125.133 milliseconds to solve this problem.
|
It took 111.346 milliseconds to solve this problem.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user