Class PE0027

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<java.lang.Integer> cache
      A memory for all found primes to save some time while checking the result of every calculation.
      private java.util.ArrayList<java.lang.Integer> primes
      A storage for all primes less than 1000.
    • Constructor Summary

      Constructors 
      Constructor Description
      PE0027()
      A simple constructor to set number and title.
    • Method Summary

      Modifier and Type Method Description
      void prepare()
      Initializes the primes and cache memories.
      java.lang.String solve()
      This method solves the given problem by running three nested loops.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • primes

        private java.util.ArrayList<java.lang.Integer> primes
        A storage for all primes less than 1000.
      • cache

        private java.util.ArrayList<java.lang.Integer> cache
        A memory for all found primes to save some time while checking the result of every calculation.
    • Constructor Detail

      • PE0027

        public PE0027()
        A simple constructor to set number and title.
    • Method Detail

      • prepare

        public void prepare()
        Initializes the primes and cache memories. Both have the primes less than 1000 as base. A Sieve is used to get them.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
        See Also:
        Sieve
      • solve

        public java.lang.String solve()
        This method solves the given problem by running three nested loops. The outer loop steps over all primes and set them as b. A second loop increments a from 1-b to 999. A the inner loop uses the variable n starting by 0 to find the maximum number of primes in a row. Every calculated result is is checked to be a prime or can be found on cache.
        Returns:
        the product of a and b with the maximum n
        See Also:
        Mathe.isPrime(int)