Friday, July 8, 2022
HomeSoftware DevelopmentDepend of components altering which adjustments the GCD of Array

Depend of components altering which adjustments the GCD of Array


  

#embody <bits/stdc++.h>

#outline ll lengthy lengthy

utilizing namespace std;

  

ll GCD(ll a, ll b)

{

    if (!b)

        return a;

    return GCD(b, a % b);

}

  

ll discover(ll* prefix, ll* suffix, ll i, ll n)

{

    

    if (i == 0) {

        return suffix[1];

    }

  

    

    if (i == n - 1) {

        return prefix[n - 2];

    }

  

    

    else {

        return GCD(prefix[i - 1], suffix[i + 1]);

    }

}

  

ll findCount(ll* arr, ll n)

{

    ll i, Depend = 0;

  

    ll prefix[n];

    ll suffix[n];

  

    prefix[0] = arr[0];

    suffix[n - 1] = arr[n - 1];

  

    

    for (i = 1; i < n; i++) {

        prefix[i] = GCD(prefix[i - 1], arr[i]);

    }

  

    

    for (i = n - 2; i >= 0; i--) {

        suffix[i] = GCD(suffix[i + 1], arr[i]);

    }

  

    

    

    for (i = 0; i < n; i++) {

  

        

        

        

        

        if (discover(prefix, suffix, i, n) > 1)

            Depend++;

    }

  

    return Depend;

}

  

int important()

{

    ll arr[] = { 3, 6, 9 };

    ll N = sizeof(arr) / sizeof(arr[0]);

  

    

    cout << findCount(arr, N);

    return 0;

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments