본문으로 바로가기
728x90
반응형


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.math.BigInteger;                                      //int의 범위를 넘는 수가 나오므로 biginteger 사용
class Solution {
  public BigInteger solution(int balls, int share) {
        
        return fac(balls).divide((fac(balls-share).multiply(fac(share)))); //hint 에 써있는 공식대로 입력
    }
    
    public BigInteger fac(int num) {                                //팩토리얼을 실행해주는 메소드
        BigInteger big=new BigInteger("1");                         //1부터 시작
        for(int i=1; i<=num; i++) {
            big=big.multiply(new BigInteger(Integer.toString(i)));  //1부터 n까지 차례대로 곱해줌
        }
        return big;
    }
 
}
cs
반응형

 

728x90
반응형