코딩왕랄프👊🏻

[백준] 2231번 분해합 본문

백준

[백준] 2231번 분해합

hyerm_2 2022. 4. 11. 21:48
반응형
SMALL

https://www.acmicpc.net/problem/2231

 

2231번: 분해합

어떤 자연수 N이 있을 때, 그 자연수 N의 분해합은 N과 N을 이루는 각 자리수의 합을 의미한다. 어떤 자연수 M의 분해합이 N인 경우, M을 N의 생성자라 한다. 예를 들어, 245의 분해합은 256(=245+2+4+5)이

www.acmicpc.net

 

 

 

import java.util.*;
 

class Main {
	public static void main(String[] args) {		 
		Scanner sc=new Scanner(System.in);
		int n= sc.nextInt();
        int i=0;
        int total=0;

		for(i=0;i<n;i++) {
			int sum=0;
			int num=i;
			
			while(num!=0) {
				sum+=num%10;
				num/=10;
			}
			if(n==sum+i) {
                total=i;
                break;
            }
		}
		System.out.println(total);
	}
}
반응형
LIST

'백준' 카테고리의 다른 글

[백준] 1065번 한수  (0) 2022.04.12
[백준] 4673번 셀프 넘버  (0) 2022.04.12
[백준] 11724번 연결요소의 개수  (0) 2022.04.03
[백준] 7576번 토마토  (0) 2022.03.29
[백준] 1260번 DFS와 BFS  (0) 2022.03.26