I have an array of numbers. I want to calculate $GCD$ of all numbers but excluding numbers from particular index $a$ to index $b$.
I need to repeat the same operation multiple times with different values of $a$ and $b$.
Is there any better way other than the obvious $Brute Force$ one?
2026-04-02 03:52:32.1775101952
Finding $GCD$ excluding some elements from an $array$
820 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
1
Note that the GCD of (integer?) array elements
c[1..n]excludingc[a..b]is the GCD of the two values, GCD ofc[1..(a-1)]and GCD ofc[(b+1)..n].So if you formed the (descending) sequence of GCD's of the initial segments
c[1..k]and those of the terminal segmentsc[m..n], you would be able to find all the queries of GCD's excluding some intervening segmentc[a..b]in constant time (taking the GCD of two previously computed results).