[Swiftアルゴリズム]約数の個数と加算


https://programmers.co.kr/learn/courses/30/lessons/77884
import Foundation

func solution(_ left:Int, _ right:Int) -> Int {

    var answer = 0

    for i in left...right {
        var num = 0
        for j in 1...i {
            if i % j == 0 {
                num += 1
            }
        }

        if num % 2 == 0 {
            answer += i
        } else {
            answer -= i
        }

    }

    return answer
}