티스토리 뷰
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int result = 1;
while(n != 0) {
result *= n;
n--;
}
System.out.println(result);
}
}
간단.
10! = 3628800 이므로 시간복잡도가 계승으로 나올 때는 답이 없다는 것을 알 수 있다.
var n = Int(readLine()!)!
var result = 1
for i in stride(from: 1, through: n, by: 1) {
result *= i
}
print(result)
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
2004번 '조합 0의 개수' (0) | 2018.08.01 |
---|---|
1676번 '팩토리얼 0의 개수' (0) | 2018.08.01 |
11653번 '소인수분해' (0) | 2018.08.01 |
6588번 '골드바흐의 추측' (0) | 2018.08.01 |
1929번 '소수 구하기' (0) | 2018.08.01 |
댓글