문제 링크

4673번: 셀프 넘버 (acmicpc.net)

 

4673번: 셀프 넘버

셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때,

www.acmicpc.net



#include <iostream>
using namespace std;
#define SIZE 10000
int main()
{
    int d, temp;
    bool a[SIZE + 1] = {};
    for (int i = 1; i <= SIZE; i++)
    {
        temp = i;
        d = i;
        while (temp)
        {
            d += temp % 10;
            temp /= 10;
        }
        if (d <= SIZE)
        {
            a[d] = true;
        }
    }
    for (int i = 1; i <= SIZE; i++)
    {
        if (!a[i])
        {
            printf("%d\n", i);
        }
    }
}

+ Recent posts