Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
7
Indexable
Never
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.Scanner;

class HelloWorld {
    static boolean isPrime(int num) {
        boolean result = false;

        for(int i=2; i<num/2; i++) {
            if(num%i == 0) {
                result = false;
                return result;
            }
        }

        return true;
    }

    static int findPrimoNumbers(int a[], int n) {
        int count = 0;
        boolean increasedFlag = false;

        for(int i=0; i<n; i++) {
            if((a[i] == 1 || isPrime(a[i]+1)) && increasedFlag == false) {
                count++;
                increasedFlag = true;
            }

            else if(isPrime(a[i])) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int a[] = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }

        int i = findPrimoNumbers(a, n);
        System.out.println(i);
    }
}