Last active
May 10, 2018 05:43
-
-
Save BrendenHJH/e2861fc03ae62a05886a917ba0ade6f4 to your computer and use it in GitHub Desktop.
백준 4673 셀프 넘버
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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