Hayden's Archive
[알고리즘] 백준 4673번 : 셀프 넘버 본문
알고리즘 문제 출처 : https://www.acmicpc.net/problem/4673
4673번: 셀프 넘버
문제 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌�
www.acmicpc.net
내가 작성한 코드
public class Main {
private static int notSelfNum (int n) {
int total = n;
int quotient = n;
while(quotient > 0) {
total += quotient % 10;
quotient /= 10;
}
return total;
}
public static void main(String[] args) {
boolean [] check= new boolean[10001];
for(int i=1; i<check.length; i++) {
if(notSelfNum(i)<10001) check[notSelfNum(i)] = true;
}
for(int i=1; i < check.length; i++) {
if(check[i]==false) System.out.println(i);
}
}
}