-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[코딩테스트 연습 - 약수의 개수와 덧셈](https://school.programmers.co.kr/learn/courses/30/lessons/77884)
💬 풀이
import Foundation
func solution(left:Int, right:Int) -> Int {
var result = 0
guard left != 0 && right != 0 else { return 0 }
for i in left...right {
result = getDivisor(i) ? result + i : result - i
}
return result
}
func getDivisor(_ n: Int) -> Bool {
var count = 0
for i in 1...n {
if n % i == 0 {
count += 1
}
}
return count % 2 == 0 ? true : false
}