Post

[BaekJoon] 26711번 - A+B [Java]

[BaekJoon] 26711번 - A+B [Java]

문제 링크


1. 문제 풀이


두 정수 $A$, $B$ 의 합을 구하는 문제로 수의 범위가 최대 $5,000$ 자리로 매우 크다. 큰 수를 다룰 수 있는 도구나 라이브러리를 활용하면 간단하게 해결할 수 있다.


2. 코드


1. 풀이 [Java]

큰 정수의 연산을 처리할 수 있는 BigInteger 클래스를 활용했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        BigInteger A = new BigInteger(br.readLine());
        BigInteger B = new BigInteger(br.readLine());

        System.out.println(A.add(B));
    }
}

This post is licensed under CC BY 4.0 by the author.