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 firstNum = BigInteger.Parse(Console.ReadLine());
- BigInteger secondNum = BigInteger.Parse(Console.ReadLine());
- BigInteger thirdNum = BigInteger.Parse(Console.ReadLine());
- int n = int.Parse(Console.ReadLine());
- int deviser = n % 3;
- if (deviser == 1)
- {
- n += 2;
- }
- else if (deviser == 2)
- {
- n++;
- }
- int numberOfCycles = (n / 3) - 1;
- for (int i = 0; i < numberOfCycles; i++)
- {
- firstNum = firstNum + secondNum + thirdNum;
- secondNum = secondNum + firstNum + thirdNum;
- thirdNum = thirdNum + firstNum + secondNum;
- }
- if (deviser == 0)
- {
- Console.WriteLine(thirdNum);
- }
- else if (deviser == 1)
- {
- Console.WriteLine(firstNum);
- }
- else
- {
- Console.WriteLine(secondNum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement