/**
 * Given two sets of integers, return a set containing their common factors.
 *
 * @param setA Set of integers
 * @param setB Set of integers
 * @return Set containing common factors of setA and setB
 *
 * Example:
 * calculateCommonFactors(setOf(1, 2, 3, 4), setOf(2, 4, 6, 8)) => setOf(2, 4)
 */
fun calculateCommonFactors(setA: Set<Int>, setB: Set<Int>): Set<Int> {

    val commonFactors = mutableSetOf<Int>()

    for (num in setA) {
        if (setB.all { num % it == 0 }) {
            commonFactors.add(num)
        }
    }

    return commonFactors
}
/**
 * Given two sets of integers, return a set containing their common factors.
 *
 * @param setA Set of integers
 * @param setB Set of integers
 * @return Set containing common factors of setA and setB
 *
 * Example:
 * calculateCommonFactors(setOf(1, 2, 3, 4), setOf(2, 4, 6, 8)) => setOf(2, 4)
 */
fun calculateCommonFactors(setA: Set<Int>, setB: Set<Int>): Set<Int> {
/**
 * Given two sets of integers, return a set containing their common factors.
 *
 * @param setA Set of integers
 * @param setB Set of integers
 * @return Set containing common factors of setA and setB
 *
 * Example:
 * calculateCommonFactors(setOf(1, 2, 3, 4), setOf(2, 4, 6, 8)) => setOf(2, 4)
 */
fun calculateCommonFactors(setA: Set<Int>, setB: Set<Int>): Set<Int> {

    val commonFactors = mutableSetOf<Int>()

    for (num in setA) {
        if (setB.all { num % it == 0 }) {
            commonFactors.add(num)
        }
    }

    return commonFactors
}