sm 기술 블로그

112. 11051(이항 계수 2) 본문

문제/백준_자바

112. 11051(이항 계수 2)

sm_hope 2022. 6. 26. 21:15
import java.util.*;
import java.io.*;
import java.math.BigInteger;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] sBits = br.readLine().split(" ");
		BigInteger N = BigInteger.valueOf(Integer.parseInt(sBits[0]));
		int A = Integer.parseInt(sBits[0]);
		BigInteger K = BigInteger.valueOf(Integer.parseInt(sBits[1]));
		int B = Integer.parseInt(sBits[1]);

		if (B == 0) {
			System.out.println(1);
		} else {
			for (int i = 1; i < B; i++) {
				N = N.multiply(BigInteger.valueOf(A - i));
				K = K.multiply(BigInteger.valueOf(B - i));
			}

			BigInteger afterBigNum = (N.divide(K)).remainder(BigInteger.valueOf(10007));
					
			int int_bigNum = afterBigNum.intValue();

			System.out.println(int_bigNum % 10007);
		}

	}
}

문제요약

이항계수를 구하고 거기에 10007을 나눈 나머지를 구하라

설명

자세한 로직설명은 아래를 참고하자

https://smhope.tistory.com/294?category=1058419 

 

111. 11050 (이항계수 1)

import java.util.*; import java.io.*; class Main { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sBit..

smhope.tistory.com

 

이번 문제에서는 다시는 안 쓸 줄 알았던 BigInteger를 사용하였다.

물론 배열을 이용한 더 쉬운 방법이 있을 수 있지만, 현재는 이 방법이 더 편한 것 같다.

 

BigInteger에 대한 자세한 설명은

https://smhope.tistory.com/297?category=1052317 

 

[Java] BigInteger

BigInteger란? int나 double은 크기 제한이 있기 때문에 매우매우 큰 수는 표현이 불가능하다. 그에 반해 BigInteger는 문자열 형태로 이루어져있기 때문에 숫자 범위를 무한하게 표현이 가능하다. 선언 /

smhope.tistory.com

 

'문제 > 백준_자바' 카테고리의 다른 글

114. 9375 (패션왕 신해빈)  (0) 2022.06.27
113. 1010 (다리놓기)  (0) 2022.06.26
111. 11050 (이항계수 1)  (0) 2022.06.26
110. 3036 링  (0) 2022.06.25
109. 2981(검문)  (0) 2022.06.25
Comments