728x90
반응형
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger a = scanner.nextBigInteger();
BigInteger b = scanner.nextBigInteger();
System.out.println(a.divide(b));
System.out.println(a.remainder(b));
}
}
문제점 :
10의 1000승까지 출력돼야하는데 int, long 등은 출력하지 못함.
그렇기 때문에 무한한 수를 출력할 수 있는 BigInteger를 사용함.
대신, BigInteger은 사칙연산이 불가능하기 때문에 함수를 이용하여 계산해야함.
728x90
반응형
'백준' 카테고리의 다른 글
[JAVA] 백준 2420번 사파리월드 (0) | 2023.02.17 |
---|---|
[JAVA] 백준 1330번 두 수 비교하기 (0) | 2023.02.17 |
[JAVA] 백준 1152번 단어의 개수 (0) | 2023.02.14 |
[JAVA] 백준 1008번 A/B (0) | 2023.02.14 |
[JAVA] 백준 1001번 A-B (0) | 2023.02.14 |
728x90
반응형
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BigInteger a = scanner.nextBigInteger();
BigInteger b = scanner.nextBigInteger();
System.out.println(a.divide(b));
System.out.println(a.remainder(b));
}
}
문제점 :
10의 1000승까지 출력돼야하는데 int, long 등은 출력하지 못함.
그렇기 때문에 무한한 수를 출력할 수 있는 BigInteger를 사용함.
대신, BigInteger은 사칙연산이 불가능하기 때문에 함수를 이용하여 계산해야함.
728x90
반응형
'백준' 카테고리의 다른 글
[JAVA] 백준 2420번 사파리월드 (0) | 2023.02.17 |
---|---|
[JAVA] 백준 1330번 두 수 비교하기 (0) | 2023.02.17 |
[JAVA] 백준 1152번 단어의 개수 (0) | 2023.02.14 |
[JAVA] 백준 1008번 A/B (0) | 2023.02.14 |
[JAVA] 백준 1001번 A-B (0) | 2023.02.14 |