알고리즘/백준

[java] 백준 10757번 큰 수 A+B

펄찌 2021. 7. 21. 22:01

import java.math.BigInteger;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        BigInteger A = sc.nextBigInteger();
        BigInteger B = sc.nextBigInteger();

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


}

int는 메모리 크기는 4byte로 표현할 수 있는 범위는 -2,147,483,648 ~ 2,147,483,647 이고

long은 메모리 크기는 8byte로 표현할 수 있는 범위는 -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 이다.

 

하지만 그 범위를 넘어서게 되면 모두 0으로 출력이 된다.

 

숫자의 범위가 무한한 BigInteger란 클래스를 쓰면 쉽게 풀 수 있다.

 

 

반응형