const fs = require('fs');
const path = process.platform === 'linux' ? '/dev/stdin' : './data.txt';
const input = fs.readFileSync(path).toString().trim().split(' ');
function solve(input) {
let [A, B] = input.map((x) => BigInt(x));
return String(A + B);
}
console.log(solve(input));
์ซ์๊ฐ ๋๋ฌด ํด ๋, ์ ํ์ด ์๋ค๋ ๊ฒ
ex) 9223372036854775807์ ๊ฒฝ์ฐ 9223372036854776000์ผ๋ก ๋์จ๋ค.
๊ทธ๋ด ๋, BigInt๋ฅผ ์ฌ์ฉํ๋ค.
(BigInt๋ Number ์์ ๊ฐ์ด ์์ ์ ์ผ๋ก ๋ํ๋ผ ์ ์๋ ์ต๋์น์ธ 2^53 - 1๋ณด๋ค ํฐ ์ ์๋ฅผ ํํํ ์ ์๋ ๋ด์ฅ ๊ฐ์ฒด)
๊ทธ๋ฅ ์ถ๋ ฅํ๋ฉด ๋ค์ n ๊ฐ์ด ์๊ธฐ ๋๋ฌธ์ ๋ฌธ์ํ์ผ๋ก ๋ฐ๊ฟ์ค๋ค.
'๐ JavaScript > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JS] 2581 (0) | 2022.05.22 |
---|---|
[JS] 1978 (0) | 2022.05.22 |
[JS] 2839 (0) | 2022.05.21 |
[JS] 2775 (0) | 2022.05.21 |
[JS] 10250 (0) | 2022.05.19 |