#include <iostream>
#include <vector>
using namespace std;
const int MAX = 10001;
int plusK(int k){
int result = 0;
while(k > 0){
result += k%10;
k /= 10;
}
return result;
}
int main()
{
vector<bool> v(MAX, true);
for(int i=1; i<MAX; i++){
if(v[i] == false) continue; //셀.넘 아니면 검사 x
//else : i는 셀.넘
int j = i;
while(j < MAX){
j = j+plusK(j);
v[j] = false;
}
}
for(int i=1; i<MAX; i++){
if(v[i] == true)
cout << i << "\n";
}
return 0;
}
10,000보다 작거나 같은 셀프 넘버를 한 줄에 하나씩 증가하는 순서로 출력한다.
100보다 작은 셀프 넘버는 총 13개가 있다. 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, 97
입력이 없는 문제는 첨 봤다 ㄷㄷ
셀프 넘버. 소수 탐색할 때처럼 지워주면 되려나? 주어진 13개를 생성자로 해서 지워주면 될 것도 같다.
그럼 일단 d(n)에 대한 함수를 코드로 정의해볼까?
dn = n + n%10 + n/10%10... (자릿수 더하는 코드)