인프런 커뮤니티 질문&답변
오답이 뜨는 이유
작성
·
355
0
안녕하세요! 수학적 풀이에 사용된 코드를 조금 풀어 써 보았는데 오답이 뜨는 이유를 잘 모르겠습니다.
public static int solution(int n) {
int answer=0, subsum=1;
int cnt=1; //연속된 자연수 개수
while(subsum<n){
subsum += (++cnt);
int tmp = n - subsum;
if(tmp%cnt ==0){
System.out.println(cnt+" subsum:"+subsum+ " tmp:"+tmp);
answer++;
}
}
return answer;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
System.out.println(solution(n));
}






감사합니다 선생님 ㅠ 미처 신경쓰지 못했네요