Skip to content

Instantly share code, notes, and snippets.

@boyanov83
Created July 29, 2014 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boyanov83/c084cb4510e0ffec7adb to your computer and use it in GitHub Desktop.
Save boyanov83/c084cb4510e0ffec7adb to your computer and use it in GitHub Desktop.
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