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 (cpp):
// C++ code to implement the approach
#include <bits/stdc++.h>
using namespace std;

// Function to find gcd of two numbers
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
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
int main()
{
    int A[] = {1, 2, 3, 4, 5};
    int N = sizeof(A) / sizeof(A[0]);
    int K = 3;

    // Function call
    cout << (find(A, N, K));
}