# 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);
}
``````

}
{"ft_lang_label":"__label__en","ft_lang_prob":0.8280011,"math_prob":0.99614996,"size":734,"snap":"2021-21-2021-25","text_gpt3_token_len":209,"char_repetition_ratio":0.1630137,"word_repetition_ratio":0.013986014,"special_character_ratio":0.29836512,"punctuation_ratio":0.0738255,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9991534,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-06-16T01:48:53Z\",\"WARC-Record-ID\":\"<urn:uuid:02d496a9-3b0f-4deb-b705-51f6577917f0>\",\"Content-Length\":\"13963\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1056b4d1-4042-421d-9503-37ba118761a8>\",\"WARC-Concurrent-To\":\"<urn:uuid:19b04aa5-bfaf-4625-9d01-bf68137fe6c4>\",\"WARC-IP-Address\":\"54.165.214.21\",\"WARC-Target-URI\":\"https://discuss.codechef.com/t/zerofy-array/84031\",\"WARC-Payload-Digest\":\"sha1:GUHTXLWGNBT4WZWDVPDZF4P3MEWMIEU2\",\"WARC-Block-Digest\":\"sha1:PPYOUYUHX6XC2QG2LLKKQBHWKTIDI37U\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-25/CC-MAIN-2021-25_segments_1623487621699.22_warc_CC-MAIN-20210616001810-20210616031810-00080.warc.gz\"}"}