stkirov

Tribonacci

Oct 16th, 2012
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics; //use for the BigInteger
  4.  
  5. class Program
  6. {
  7.     static void Main()
  8.     {
  9.         BigInteger t1 = BigInteger.Parse(Console.ReadLine());
  10.         BigInteger t2 = BigInteger.Parse(Console.ReadLine());
  11.         BigInteger t3 = BigInteger.Parse(Console.ReadLine());
  12.         BigInteger n = BigInteger.Parse(Console.ReadLine());
  13.         BigInteger final = 0;
  14.  
  15.         if (n==1)
  16.         {
  17.             final = t1;
  18.         }
  19.         else if (n == 2)
  20.         {
  21.             final = t2;
  22.         }
  23.         else if (n == 3)
  24.         {
  25.             final = t3;
  26.         }
  27.         for (BigInteger i = 0; i < n - 3; i++)
  28.         {
  29.             final = t1 + t2 + t3;
  30.             t1 = t2;
  31.             t2 = t3;
  32.             t3 = final;
  33.         }
  34.         Console.WriteLine(final);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment