Advertisement
Guest User

Tribonacci

a guest
Jul 29th, 2014
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class SimpleLoops
  5. {
  6.     static void Main()
  7.     {
  8.         BigInteger t1 = int.Parse(Console.ReadLine());
  9.         BigInteger t2 = int.Parse(Console.ReadLine());
  10.         BigInteger t3 = int.Parse(Console.ReadLine());
  11.         BigInteger n = int.Parse(Console.ReadLine());
  12.  
  13.         BigInteger Tn = t3 + t2 + t1;
  14.  
  15.         if (n < 4)
  16.         {
  17.             if (n == 1)
  18.             {
  19.                 Tn = t1;
  20.             }
  21.             else if (n == 2)
  22.             {
  23.                 Tn = t2;
  24.             }
  25.             else
  26.             {
  27.                 Tn = t3;
  28.             }
  29.         }
  30.         else
  31.         {
  32.             for (int i = 4; i < n; i++)
  33.             {
  34.                 t1 = t2;
  35.                 t2 = t3;
  36.                 t3 = Tn;
  37.                 Tn = t3 + t2 + t1;
  38.             }
  39.         }
  40.  
  41.         Console.WriteLine(Tn);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement