백준 브론즈5를 풀다가 숫자를 나누려하는데 나누기가 되지 않는 상황 발생
그 이유는 사용가능 범위를 초과하였기 때문
그래서 BigInteger을 사용하여야 한다.
https://learn.microsoft.com/ko-kr/dotnet/api/java.math.biginteger?view=net-android-34.0
BigInteger 클래스 (Java.Math)
변경할 수 없는 임의 정밀도 정수입니다.
learn.microsoft.com
하지만 BigInteger은 산술 연산자를 사용하지 못하는데
그 이유는 객체이기 때문이다.
자바는 연산자 오버로딩을 지원하지 않는다.
따라서 우리는 이런 식으로 사용해야 한다.
백준에서는 클래스명을 Main으로 쓰지 않으면 컴파일 에러가 난다.
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger n = sc.nextBigInteger();
BigInteger m = sc.nextBigInteger();
System.out.println(n.divide(m));
System.out.println(n.remainder(m));
sc.close();
}
}