매일코테

백준 5단계 no.2

공주맛밤 2022. 7. 23. 12:34

public class Main{
    static int progression(int k) {
        int m = k;
        int sum = 0;

        while (k != 0) {
            sum += k % 10;
            k /= 10;
        }

        return sum + m;
    }

    public static void main(String[] args) {
        int[] a = new int[10000];

        for (int i = 0; i < a.length; i++) {
            a[i] = i + 1;
        }

        for (int j = 0; j < a.length; j++) {

            if (a[j] != 0) {
                int p = a[j];

                while (p <= 10000) {
                    p = progression(p);
                    if (p < 10000) {
                        a[p - 1] = 0;
                    }
                }
            }
        }

        for (int l = 0; l < (a.length-1); l++) {
            if (a[l] != 0)
            System.out.println(a[l]);
        }
    }
}
728x90
반응형

'매일코테' 카테고리의 다른 글

백준 6단계 no.1  (0) 2022.07.23
백준 5단계 no.3  (0) 2022.07.23
백준 5단계 no.1  (0) 2022.07.22
백준 4단계 no.7  (0) 2022.07.22
백준 4단계 no. 6  (0) 2022.07.22