Class PE0037

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<java.lang.Integer> candidates
      List of all primes less that 1,000,000.
    • Constructor Summary

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

      Modifier and Type Method Description
      void prepare()
      Just initializes the attributes and stores all primes less than 1,000,000 in candidates if the do not start with 4, 6, or 8, and do not end with 0, 2, 4, 6, or 8.
      java.lang.String solve()
      Every candidate is proved by method test(int).
      private boolean test​(int num)
      Truncates the given number from both sides and tests if the both new numbers are primes (are stored in candidates).
      • Methods inherited from class java.lang.Object

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

      • candidates

        private java.util.ArrayList<java.lang.Integer> candidates
        List of all primes less that 1,000,000.
    • Constructor Detail

      • PE0037

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

      • prepare

        public void prepare()
        Just initializes the attributes and stores all primes less than 1,000,000 in candidates if the do not start with 4, 6, or 8, and do not end with 0, 2, 4, 6, or 8.
        Specified by:
        prepare in interface Solvable
        Overrides:
        prepare in class Problem
        See Also:
        Sieve
      • solve

        public java.lang.String solve()
        Every candidate is proved by method test(int). If it returns true and the number is greater zero it is summed to the searched result.
        Returns:
        the sum of all primes that are tested true
      • test

        private boolean test​(int num)
        Truncates the given number from both sides and tests if the both new numbers are primes (are stored in candidates).
        Parameters:
        num - the number to be tested
        Returns:
        true if, and only if the number can be truncated from left and right and all resulting numbers are primes