로직
python으로 풀어서..
N = int(input())
result = [] # 문자열로 하면 메모리 절약
if(N != 1):
i = 2
end = N
while(end > 1):
if(end % i != 0):
i += 1
continue
result.append(i)
end = end // i
for i in result:
print(i)
Javascript로 변경해 봤다.
let N = parseInt(prompt("Enter a number"));
let result = []; // Using array instead of string to save memory
if(N !== 1){
let i = 2;
let end = N;
while(end > 1){
if(end % i !== 0){
i += 1;
continue;
}
result.push(i);
end = end / i;
}
for(let i = 0; i < result.length; i++){
console.log(result[i]);
}
}
모르는 거
1) 소수를 어떻게 구하는가..?
while(N>1):
for i in range(2, N+1):
if N%i==0:
print(i)
N = N/i
break # 다시 2부터 시작한다!
}
}
break
가 핵심이었다..!