알고리즘/백준 - JAVA
-
[백준(JAVA)] 1676 : 팩토리얼 0 의 개수 - BigInteger알고리즘/백준 - JAVA 2023. 11. 29. 20:00
https://www.acmicpc.net/problem/1676 문제 풀기 전 팩토리얼 500이 얼마나 큰 숫자일지 가늠해보기 위해서 웹 상에 있는 팩토리얼 계산기를 통해 확인해보았다 대략적으로만 봐도 21억 (int 형의 표현 범위 약 ±21억) 은 기본으로 넘는 숫자인걸 확인할 수 있다 아무리 봐도 int 형에는 담기지 않을 것 같아서 long 형으로 구현을 시도해보았으나 long 형 또한 20! 이후로는 계산 값이 정확히 나오지 않았다 따라서 더 큰 수를 담을 수 잇는 자료형을 확인하기로 했다 BigInteger 클래스 java.math 패키지의 BigInteger 클래스 API 문서의 앞 부분을 읽어보면, 불변의 임의의 정밀도 정수 모든 연산들은 마치 BigInteger 가 자바의 원시 int ..