Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- class Tribonacci
- {
- static void Main()
- {
- BigInteger firstNumber = int.Parse(Console.ReadLine());
- BigInteger secondNumber = int.Parse(Console.ReadLine());
- BigInteger thirdNumber = int.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- BigInteger result = 0;
- if (n == 1)
- {
- Console.WriteLine(firstNumber);
- }
- else if (n == 2)
- {
- Console.WriteLine(secondNumber);
- }
- else if (n == 3)
- {
- Console.WriteLine(thirdNumber);
- }
- else
- {
- for (int i = 4; i <= n; i++)
- {
- result = firstNumber + secondNumber + thirdNumber;
- firstNumber = secondNumber;
- secondNumber = thirdNumber;
- thirdNumber = result;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement