Written by
java-style
on
on
[백준][JAVA] 큰 수 A+B
[백준][JAVA] 큰 수 A+B
https://www.acmicpc.net/problem/10757
import java.math.BigInteger; import java.util.Scanner; public class Q10757 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); BigInteger A = new BigInteger(scan.next()); BigInteger B = new BigInteger(scan.next()); A = A.add(B); System.out.println(A); } }
자바에서 제공하는 BigInteger 클래스를 활용하여 풀면 간단하다!
이론 - BigInteger
BigInteger 클래스?
자바의 64bit 정수형보다 더 큰 수를 저장할 때 사용하는 클래스. 숫자의 크기에 제한이 없다.
* 자바 API 설명 : BigInteger: Immutable arbitrary-precision integers. (불변한 임의의 정말한 정수)
기본 자료형과는 달리 사칙연산 기호를 사용하여 연산을 할 수 없다.
따라서, 메소드를 활용한 연산이 이루어진다.
+ -> add()
- -> subtract()
* -> multiply()
/ -> divide()
from http://sillutt.tistory.com/132 by ccl(A) rewrite - 2021-12-19 14:28:21