/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; public class Solution { static int div=0; public static boolean isPrime(long num){ int top = (int)Math.sqrt(num) + 1; for(int i = 3; i < top; i+=2){ if(num % i == 0){ div=i; return false; } } return true; } static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. long[] f = new long[a.length]; long p=0; long r=0; for (int i=0;i0){ if(f[i]==1){ f[i]=0; } else if(f[i]%2==0){ r=r+(f[i]/2); f[i]=f[i]/2; } else if(isPrime(f[i])){ r++; f[i]=0; } else{ f[i]=f[i]/div; r=r+f[i]; } } f[i]=r; } for(int i=0;i