Guest User

Untitled

a guest
Apr 26th, 2025
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. console.time('Fibonacci');
  2. const n = 1000;
  3. let a = 0n, b = 1n;
  4.  
  5. if (n === 1) {
  6.     a = 0n;
  7. } else if (n === 2) {
  8.     b = 1n;
  9. } else {
  10.     for (let i = 3; i <= n; i++) {
  11.         [a, b] = [b, a + b];
  12.     }
  13. }
  14.  
  15. console.timeEnd('Fibonacci');
  16. console.log(`Последнее число: ${n === 1 ? a.toString() : b.toString()}`);
  17.  
Advertisement
Add Comment
Please, Sign In to add comment