[BOJ][10872] 팩토리얼
Updated:
1. 문제 링크
https://www.acmicpc.net/problem/10872
2. 사용 알고리즘
수학
3. 풀이
n부터 1까지 차례대로 곱해서 팩토리얼 계산
4. 소스 코드
4-1. C++
https://github.com/dev-aiden/problem-solving/blob/main/boj/10872.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
int ans = 1;
for (int i = n; i >= 1; --i) ans *= i;
cout << ans << "\n";
return 0;
}
4-2. JAVA
https://github.com/dev-aiden/problem-solving/blob/main/boj/10872.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int ans = 1;
for(int i = n; i >= 1; --i) ans *= i;
System.out.println(ans);
}
}
Leave a comment