Class PE0021

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.ArrayList<java.lang.Long> cache
      Stores all found amicable numbers.
    • Constructor Summary

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

      Modifier and Type Method Description
      private boolean isAmicable​(long num)
      Checks the given number to be a amicable number.
      void prepare()
      Just initializes the cache as empty memory.
      java.lang.String solve()
      Runs a loop to 10000 and checks if the current number is amicable.
      • Methods inherited from class java.lang.Object

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

      • cache

        java.util.ArrayList<java.lang.Long> cache
        Stores all found amicable numbers.
    • Constructor Detail

      • PE0021

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

      • solve

        public java.lang.String solve()
        Runs a loop to 10000 and checks if the current number is amicable. A found amicable number is added to final sum.
        Returns:
        the sum of all found amicable numbers
        See Also:
        isAmicable(long)
      • isAmicable

        private boolean isAmicable​(long num)
        Checks the given number to be a amicable number. Therefore first the cache is asked. If the number could not be found in cache the sum of divisors is calculated.
        Parameters:
        num - the number to be checked
        Returns:
        true if the number is amicable
        See Also:
        Mathe.getSumOfDivisors(long)