230808 기사단원의 무기

Jongleee·2023년 8월 8일
0

TIL

목록 보기
332/576
public int solution(int number, int limit, int power) {
	int answer = 0;

	for (int i = 1; i <= number; i++) {
		int count = countDivisors(i);
		answer += count > limit ? power : count;
	}

	return answer;
}

private int countDivisors(int num) {
	int count = 0;
	for (int j = 1; j * j <= num; j++) {
		if (j * j == num) {
			count++;
		} else if (num % j == 0) {
			count += 2;
		}
	}
	return count;
}

출처:https://school.programmers.co.kr/learn/courses/30/lessons/136798

0개의 댓글