For a whole number m, find the smallest whole number n such that m × n is a perfect square. Example: 1500 = 2 × 2 × 3 × 5 × 5 × 5; the factors 3 and 5 appear an odd number of times, so n = 3 × 5 = 15 and 1500 × 15 = 22 500 = 150².
Write PerfectSquare with two methods:
primeFactors(long number)returns anArrayList<Long>of all the prime factors, in increasing order;factorsWithOddCount(ArrayList<Long> factors)returns the different factors that occur an odd number of times.
For the input
1500
the program prints
Prime factors of 1500: [2, 2, 3, 5, 5, 5]
Factors that appear an odd number of times: [3, 5]
Smallest n: 15
1500 x 15 = 22500 = 150 squared