반응형
https://www.acmicpc.net/problem/1271
브론즈 5 문제이다.
BigInteger
- int(약 -+20억, -2,147,483,648 ~ 2,147,483,647)와
long(-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807)보다 더 큰 범위의 타입 - 무한의 정수가 들어갈 수 있는 가능성이 있다면 BigInteger이라는 클래스를 활용하는 것이 좋음
- 알고리즘 문제에서 최악의 경우를 대비하고자 사용하기도 함
- BigInteger을 초기화하려면 문자열을 인자값으로 넘겨주어야함
- 문자열이기에 사칙연산 불가능
- BigInteger 내부의 숫자계산은 BigInteger 클래스 내부에 있는 메서드 사용!
- + : add
- - : subtract
- * : multiply
- / : divide
- % : remainder, mod
전체 코드
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger N = sc.nextBigInteger();
BigInteger M = sc.nextBigInteger();
BigInteger result = new BigInteger("1000");
BigInteger result2 = new BigInteger("1000");
result = N.divide(M);
result2 = N.mod(M); //remainder
System.out.println(result);
System.out.println(result2);
}
+) BigInteger 사용 문제 : 2338번: 긴자리 계산 (acmicpc.net)
반응형
'Algorithm & Data Structure > 문제 풀이' 카테고리의 다른 글
[JAVA] baekjoon 10871 (0) | 2021.10.03 |
---|---|
[JAVA] baekjoon 15552 (0) | 2021.09.11 |
[programmers] 완주하지 못한 선수 (Python) (0) | 2021.06.22 |
[programmers] 모의고사 (Python) (0) | 2021.06.21 |
[4949] 균형잡힌 세상 (Python) (0) | 2021.06.21 |