Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- namespace Tribonacci
- {
- class Tribonacci
- {
- public static void Main(string[] args)
- {
- BigInteger tnMinus3 = BigInteger.Parse(Console.ReadLine());
- BigInteger tnMinus2 = BigInteger.Parse(Console.ReadLine());
- BigInteger tnMinus1 = BigInteger.Parse(Console.ReadLine());
- BigInteger n = BigInteger.Parse(Console.ReadLine());
- BigInteger tn = 0;
- for(int i = 4; i <= n; i++)
- {
- tn = tnMinus1 + tnMinus2 + tnMinus3;
- tnMinus3 = tnMinus2;
- tnMinus2 = tnMinus1;
- tnMinus1 = tn;
- }
- if (n == 3)
- {
- Console.WriteLine(tnMinus1);
- }
- else
- {
- Console.WriteLine(tn);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment