Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.time('Fibonacci');
- const n = 1000;
- let a = 0n, b = 1n;
- if (n === 1) {
- a = 0n;
- } else if (n === 2) {
- b = 1n;
- } else {
- for (let i = 3; i <= n; i++) {
- [a, b] = [b, a + b];
- }
- }
- console.timeEnd('Fibonacci');
- console.log(`Последнее число: ${n === 1 ? a.toString() : b.toString()}`);
Advertisement
Add Comment
Please, Sign In to add comment