백준-Node.js-10757

송철진·2023년 2월 1일
0

백준-Node.js

목록 보기
2/69

풀이 & TIL

const fs = require('fs')
const [a,b] = fs.readFileSync('/dev/stdin').toString().trim().split(" ")

const sum = (str1, str2) => {
	return `${BigInt(str1) + BigInt(str2)}`
	// return ( BigInt(str1) + BigInt(str2) ).toString() 
}

console.log( sum(a, b) )

2^53 - 1보다 큰 정수를 그냥 Number로 계산하면 뒷자리가 0들로 표시된다
BigInt로 변환해서 더하고 다시 string으로 변환하면 n이 사라진다

profile
검색하고 기록하며 학습하는 백엔드 개발자

0개의 댓글