Skip to content

Instantly share code, notes, and snippets.

@BrendenHJH
Last active May 10, 2018 05:43
Show Gist options
  • Save BrendenHJH/e2861fc03ae62a05886a917ba0ade6f4 to your computer and use it in GitHub Desktop.
Save BrendenHJH/e2861fc03ae62a05886a917ba0ade6f4 to your computer and use it in GitHub Desktop.
백준 4673 셀프 넘버
public class Main {
public static final int MAX = 10001;
public static int getNum(int x) {
int sum = x;
while(x >= 10) {
sum += x%10;
x /= 10;
}
sum += x;
return sum;
}
public static void main(String[] args) {
boolean[] isSelfNum = new boolean[MAX];
for(int i = 1; i < MAX; i++) {
for(int j = getNum(i); j < MAX; j = getNum(j)) {
if(isSelfNum[j]) continue;
isSelfNum[j] = true;
}
}
for(int i = 1; i < MAX; i++) {
if(!isSelfNum[i])
System.out.println(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment