You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

21 lines
381 B

  1. #include <stdio.h>
  2. long long tribonacci(int n) {
  3. long long a = 0, b = 1, c = 1;
  4. if (n == 0)
  5. return a;
  6. if (n == 1)
  7. return b;
  8. if (n == 2)
  9. return c;
  10. for (int i = 3; i <= n; ++i) {
  11. long long d = a + b + c;
  12. a = b, b = c, c = d;
  13. }
  14. return c;
  15. }
  16. int main() {
  17. printf("%lld\n%lld\n", tribonacci(4), tribonacci(36));
  18. }