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[] = {6, 12, 18, 24}
Sample Output: No

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