λ¬Έμ
https://www.acmicpc.net/problem/4673
νμ΄
public class μ
νλλ² {
public static void main(String[] args) {
boolean[] check = new boolean[10001];
for (int i = 1; i < 10001; i++){
int n = d(i);
if(n < 10001){
check[n] = true;
}
}
StringBuilder sb = new StringBuilder();
for (int i = 1; i < 10001; i++) {
if (!check[i]) {
sb.append(i).append('\n');
}
}
System.out.println(sb);
}
public static int d(int number){
int sum = number;
while (number != 0) {
sum = sum + (number % 10);
number = number / 10;
}
return sum;
}
}
μλ°λ‘ μ½λ©ν μ€νΈλ₯Ό λ€μ μμνκ² λμλλ° μλ°μμ μ¬μ©ν΄λ³΄μ§ μμ κ²λ€μ μ¬μ©νλ€λ³΄λ μ¬μ΄ λ¬Έμ λ€λ κ½€ μκ°μ΄ κ±Έλ Έλ€.
λ¬Έμ κ° μ΄λ €μ΄ κ² κ°μ§λ§ μμ±μκ° μλ μ ν λλ²λ§ μ°ΎμΌλ©΄ λλ€.
d(1) = 1 + 1 = 2,
d(2) = 2 + 2 = 4,
d(3) = 3 + 3 = 6 ...
μ¦ μ ν λλ²κ° μλ μλ€μ λ°°μ΄μ λ£κ³ μ ν λλ²λ₯Ό μΆλ ₯νλ©΄ λλ€.
check[2] = true, check[4] = true, check[6] = true .. μ΄λ κ² λ€μ΄κ°λ―λ‘ check[1], check[3], check[5], check[7] ... μμ μλ μΈλ±μ€κ° μ ν λλ²μ΄λ€.
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Java] [Silver5] 2941λ²_ν¬λ‘μν°μ μνλ²³ (0) | 2023.12.10 |
---|---|
π© [λ°±μ€] [Java] [Silver5] 1316λ²_κ·Έλ£Ή λ¨μ΄ 체컀 (1) | 2023.12.08 |
π© [λ°±μ€] [Python] [Silver1] 13335λ²_νΈλ (0) | 2023.06.29 |
π© [λ°±μ€] [Python] [Gold4] 15685λ²_λλκ³€ μ»€λΈ (0) | 2023.06.26 |
π© [λ°±μ€] [Python] [Gold5] 14719λ²_λΉλ¬Ό (0) | 2023.06.21 |