Baekjoon

[#2231] 분해합

강람이 2020. 3. 9. 01:39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
 
    int con = 0;
    
    for (int i = 1; i < n; i++) {
        int sum = i;
        int temp = i;
        while (true) {
            sum += temp % 10;
            temp = temp / 10;
 
            if (temp == 0) {
                if (sum == n) {
                    con = i;
                }
                break;
            }
                
        }
        if (con != 0)
            break;  //제일 작은 수 찾는거니까 바로 break;
    }
    cout << con;
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs