Problem: Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.

Sample Input: A[] = {1, 2, 3, 4, 5}, M = 3
Sample Output: Yes
?Explanation: Here, G = gcd(1, 2, 3, 4, 5) = 1.
We can choose 3 non overlapping subarrays {[1], [2, 3], [4, 5]} where
gcd(1) = 1, gcd(2, 3) = 1, and gcd(4, 5) = 1.
Thus, the average = (1 + 1 + 1)/3 = 1. Hence, we can have 3 such subarrays.

Solution (java):
// Java code to implement the approach

import java.io.*;
import java.util.*;

public class InfobayAI {

    // Function to find gcd of two numbers
    public static int gcd(int a, int b)
    {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // Function to find check whether
    // non-overlapping subarray exists
    static String find(int arr[], int n, int m)
    {
        int G = 0;
        int g = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            G = gcd(G, arr[i]);
        }
        for (int i = 0; i < n; i++) {

            // arr[i] = sc.nextInt();
            g = gcd(g, arr[i]);
            if (g == G) {
                count++;
                g = 0;
            }
        }
        if (count >= m)
            return "Yes";
        return "No";
    }

    // Driver code
    public static void main(String[] args)
    {
        int A[] = { 1, 2, 3, 4, 5 };
        int N = A.length;
        int K = 3;

        // Function call
        System.out.println(find(A, N, K));
    }
}