I have a set of integers $A = \{a:a > 0\}$ and an integer $k > 0$. I need to find $g$ of $A$, which is defined to be GCD of $A$ that is no greater than $k$. For example, if $A = \{20, 40, 60\}$ and $k = 10$, then $g$ should be $10$. Another example would be $A = \{36, 72, 90, 126\}$ and $k = 17$, in which case $g$ would be $9$.
Assume that there is already a function $f(a, b)$ that yields GCD of two positive integers $a$ and $b$. How would I go about writing an algorithm that finds $g$?