shushus

Спринт 6. Опасности экспоненты. Задание 1.

Dec 25th, 2022
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <cstdint>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int64_t T(int i) {
  7.     if (i == 0) {
  8.         return 0;
  9.     }
  10.  
  11.     int64_t prev0 = 0, prev1 = 0, prev2 = 1;
  12.  
  13.     for (int t = 1; t < i; ++t) {
  14.         int64_t next = prev0 + prev1 + prev2;
  15.         prev0 = prev1;
  16.         prev1 = prev2;
  17.         prev2 = next;
  18.     }
  19.  
  20.     return prev1;
  21. }
  22.  
  23. int main() {
  24.     int i;
  25.  
  26.     while (true) {
  27.         cout << "Enter index: "s;
  28.         if (!(cin >> i)) {
  29.             break;
  30.         }
  31.  
  32.         cout << "Ti = "s << T(i) << endl;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment