Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- class Tribonacci
- {
- static void Main(string[] args)
- {
- BigInteger firstN = BigInteger.Parse(Console.ReadLine());
- BigInteger secondN = BigInteger.Parse(Console.ReadLine());
- BigInteger thirdN = BigInteger.Parse(Console.ReadLine());
- BigInteger n = BigInteger.Parse(Console.ReadLine());
- if(n == 1)
- {
- Console.WriteLine(firstN);
- }
- else if(n == 2)
- {
- Console.WriteLine(secondN);
- }
- else if(n == 3)
- {
- Console.WriteLine(thirdN);
- }
- else
- {
- BigInteger result = 0;
- for (int i = 3; i < n; i++)
- {
- result = firstN +secondN+thirdN;
- firstN = secondN;
- secondN = thirdN;
- thirdN = result;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment