Problem Solving/Baekjoon
[백준] 4673 셀프 넘버 - Brute Force / Java
graycode
2022. 11. 20. 19:48
• 문제 링크
4673번: 셀프 넘버
셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때,
www.acmicpc.net
• 풀이 과정
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
boolean[] check = new boolean[10001];
for (int i = 1; i <= 10000; i++) {
int num = d(i);
if (num <= 10000)
check[num] = true;
}
for (int i = 1; i <= 10000; i++) {
if (!check[i])
bw.write(i + "\n");
}
bw.flush();
}
private static int d(int n) {
int sum = n;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
}