import java.util.HashMap; import java.util.Scanner; import static java.lang.Math.sqrt; public class coolProblems { static Long solve(Long l, HashMap dpMap, HashMap midDivisorMap){ if(dpMap.containsKey(l)) return dpMap.get(l); Long div=0L; if(!midDivisorMap.containsKey(l)){ // Initialize the maximum prime factor // variable with the lowest one Long maxPrime = 0L; Long n=l; // Print the number of 2s that divide n while (n % 2 == 0) { maxPrime = 2L; n >>= 1; // equivalent to n /= 2 } // n must be odd at this point, thus skip // the even numbers and iterate only for // odd integers for (long i = 3; i <= (long)sqrt(n); i += 2) { while (n % i == 0) { maxPrime = i; n = n / i; } } // This condition is to handle the case // when n is a prime number greater than 2 if (n > 2) maxPrime = n; if(!dpMap.containsKey(l/maxPrime)){ dpMap.put(l/maxPrime, solve(l/maxPrime,dpMap,midDivisorMap)); } div=maxPrime; midDivisorMap.put(l,div); } div=midDivisorMap.get(l); dpMap.put(l, dpMap.get(l/div)*div+1); return dpMap.get(l); } static long longestSequence(Long[] a) { // Return the length of the longest possible sequence of moves. HashMap dpMap=new HashMap<>(); HashMap midDivisorMap=new HashMap<>(); dpMap.put(0L,0L); dpMap.put(1L,1L); dpMap.put(2L,3L); long ans=0; for(int i=0;i