[백준알고리즘] 알고리즘 연습 - 2193

krkorklo·2022년 3월 5일
0

백준알고리즘

목록 보기
25/27

2193 - 이친수

https://www.acmicpc.net/problem/2193

let fs = require('fs');
let input = Number(fs.readFileSync('/dev/stdin').toString());

function answer(n) {
    let a = 1;
    let b = 1;
    for(let i=3; i<=n; i++) {
        let tmp = BigInt(a)+BigInt(b);
        a = b;
        b = tmp;
    }
    return b.toString();
}

console.log(answer(input));

오버플로우 나는 것 같길래 BigInt 처음 써봤다

0개의 댓글