Brilliant Numbers Thing

A brilliant number is a positive integer with exactly two prime factors where the factors contain the same number of digits. (1 is not a prime number.)

Some examples of brilliant numbers include:

  4 (2*2)
  6 (3*2)
  9 (3*3) 
 10 (5*2)
 14 (7*2)
 15 (5*3)
 21 (7*3)
 25 (5*5)
 35 (7*5)
 49 (7*7)
121 (11*11)

and so on. Note that 22 (11*2), 26 (13*2), and 33 (11*3) and many more products of two primes are not brilliant numbers because their factors have a different number of digits.

  1. Write the method isPrime(int n) that returns true if its input is a prime number. isPrime should have worst case O(sqrt(n)) time. This should go in the class in which you have public static void main(String args[]).

  2. Write a class called Primes. It should contain:
    1. A field called primes that is of type ArrayList<Integer>.
    2. A constructor that takes an integer, n, and stores the first n prime numbers in the primes field. The numbers should be stored from biggest to smallest.
      1. Example: Primes p = new Primes(6); should contain [13, 11, 7, 5, 3, 2] in the primes field.
    3. A predicate called isPrime(int n) (different from the one in problem 1) that searches the primes field for the number. If the input n is greater than the first number in the primes list, the primes list should be expanded to include all prime numbers up to n. isPrime(int n) returns true if n is a prime, false otherwise.
      1. Example: p.isPrime(26) should return false. Before it does, the primes field should be changed so it contains [23, 19, 17, 13, 11, 7, 5, 3, 2].
    4. What is the order of growth of this version of isPrime(int n)?

  3. In the class you create that has main(), create an object that stores the first 50 prime numbers.

  4. In the class with main(), write isBrilliant(int n) that returns true if n is a brilliant number and false otherwise.
    1. Write a helper method that takes two ints as its input and returns true if the number of digits for both ints is the same.

  5. Write a method that prints the first 20 brilliant numbers. You can check your work by verifying that the first eleven brilliant numbers are the same as the ones shown at the top of this page. Suggestion for this problem: Create a class called Brilliant. When you create a Brilliant object, pass it a number, n. Have the constructor call a method that will initialize an ArrayList in the Brilliant class to hold the first n brilliant numbers.