Created
July 29, 2014 13:18
-
-
Save boyanov83/c084cb4510e0ffec7adb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Numerics; | |
class Tribonacci | |
{ | |
static void Main() | |
{ | |
BigInteger tribo1 = BigInteger.Parse(Console.ReadLine()); | |
BigInteger tribo2 = BigInteger.Parse(Console.ReadLine()); | |
BigInteger tribo3 = BigInteger.Parse(Console.ReadLine()); | |
BigInteger current = 0; | |
BigInteger n = BigInteger.Parse(Console.ReadLine()); | |
if (n == 1) | |
{ | |
Console.WriteLine(tribo1); | |
} | |
else if (n == 2) | |
{ | |
Console.WriteLine(tribo2); | |
} | |
else if (n == 3) | |
{ | |
Console.WriteLine(tribo3); | |
} | |
else | |
{ | |
for (BigInteger i = 0; i < n - 3; i++) | |
{ | |
current = tribo1 + tribo2 + tribo3; | |
tribo1 = tribo2; | |
tribo2 = tribo3; | |
tribo3 = current; | |
} | |
Console.WriteLine(current); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment