GCD and Sum

Congratulations! You’ve been hired in “Buggy Softwares Ltd.” And you’ve been already given your first assignment. Initially, you’ll be given a nnn length array aaa of numbers. Then you’ll be given qqq queries of two types:

This is a companion discussion topic for the original entry at https://toph.co/p/gcd-and-sum