프로그래머스LV1 - 약수의 개수와 덧셈

Kong-al·2022년 10월 13일
0

22.10.13 D-80

프로그래머스LV1 - 약수의 개수와 덧셈

[ 답안 ]

class Solution {
	    public int solution(int left, int right) {
	        int answer=0;
            // 반복문으로 
	        for(int i=left; i<=right; i++){
	            int cnt=0;
	            for(int j=1; j<=i; j++){
	                if(i%j==0) {cnt++;}
	            }
	            answer = (cnt%2==0)? answer+i : answer-i;
	      
	        }
	        return answer;
	    }
	}
profile
웹개발 공부중!(❁´◡`❁)

0개의 댓글