์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step10] 10872 : ํŒฉํ† ๋ฆฌ์–ผ (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 19. 22:45

www.acmicpc.net/problem/10872

 

10872๋ฒˆ: ํŒฉํ† ๋ฆฌ์–ผ

0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, N!์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


๋ฌธ์ œ

0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, N!์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ •์ˆ˜ N(0 ≤ N ≤ 12)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— N!์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

10

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

3628800

 

์˜ˆ์ œ ์ž…๋ ฅ 2

0

 

์˜ˆ์ œ ์ถœ๋ ฅ 2

1


ํ’€์ด

ํŒฉํ† ๋ฆฌ์–ผ N! = N * N-1 * N-2 * … * 3 * 2 * 1

 

import java.util.Scanner;

public class B10872 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = 1;
		
		if(n == 0) {
			System.out.println("1");
		} else {
			for(int i = 1; i <= n; i++) {
				a = a * i;
			}
			System.out.println(a);
		}
	}
}