์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step8] 10757 : ํฐ ์ˆ˜ A+B (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 17. 16:15

www.acmicpc.net/problem/10757

 

10757๋ฒˆ: ํฐ ์ˆ˜ A+B

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


๋ฌธ์ œ

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A,B < 10^10000)

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„์— A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

9223372036854775807 9223372036854775808

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

18446744073709551615


ํ’€์ด

1. long ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๋Š” ์ˆ˜๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ๋Š” BigInteger ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉ

 

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

public class B10757 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		BigInteger a = new BigInteger(sc.next());
		BigInteger b = new BigInteger(sc.next());
		
		System.out.println(a.add(b));

	}
}