Zerofy array

You are given n positive array elements(including 0) , you can perform these operations on Ai any number of times ,

  1. subtract 1 from element
  2. subtract any prime number from the element
    Find the minimum number of steps required to convert all elements to zero .
    Example ;- if an array element is 4 , you can change it to 0 in following two operations -
  3. subtract 3(prime number) from 4 such that the element becomes 1
  4. subtract 1 form 1 such that the element becomes 0;
    Therefore the minimum number of operations required to change a single element 4 to 0 is 2 .

Test case 1:-
4
0 1 2 4 Output:- 4

explanation :-
for 0 required operation is 0
for 1 -> 1(subtract 1)
for 2 -> 1(subtract prime no. 2)
for 4 -> 2
therefore 0+1+1+2 = 4

import java.util.*;

public class Main
{

public static void main(String[] args) 
{
    Scanner scn = new Scanner(System.in);
    int low = 0;
    int[] arr1 = {3,6,7,8,4};
    
    Arrays.sort(arr1);
    
    int high=arr1[arr1.length-1];
    
    ArrayList<Integer> arr = new ArrayList<Integer>();
    
    for (int num = low; num <= high; num++) 
    {
        int div = 2;
        while (div * div <= num) 
        {
            if (num % div == 0) 
            {
                break;
            }
            div++;
        }
        if (div * div > num) 
        {
            arr.add(num);
        }
    }
//    Collections.sort(arr);
//    System.out.println(arr);
 int res=0;
 for(int i=0 ; i<arr1.length ; i++)
 {
     int num=arr1[i];
     while(num!=0)
     {
         int max=arr.get(0);
         for(int j=0 ; j<arr.size() ; j++)
         {
             if(arr.get(j)<=num)
             {
                 max=arr.get(j);
             }
         }
         num=num-max;
         res++;
     }
 }
 System.out.println(res);
}

}