Bomb Kirby Running
Cat Life - GT-K
77884번 약수의 개수와 덧셈

2023. 3. 28. 18:29Programmers

코딩테스트 연습 - Level 1 - 약수의 개수와 덧셈

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

#include <string>
#include <vector>

using namespace std;

int solution(int left, int right) {
    int answer = 0;
    for(int i=left;i<=right;i++)
    {
        int count=0;
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                count++;
            }
        }
        
        if(count%2==0)
        {
            answer+=i;
        }
        
        else
        {
            answer-=i;
        }
    }
    return answer;
}
​

'Programmers' 카테고리의 다른 글

1845번 폰켓몬  (0) 2023.03.28
2019 Kakao Blind Recruitment - 실패율  (0) 2023.03.28
68935번 3진법 뒤집기  (0) 2023.03.28
12982번 예산  (0) 2023.03.28
68644번 두 개 뽑아서 더하기  (0) 2023.03.28