Advertisement
koksibg

Tribonacci Number

Jul 24th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace Simple_Loops
  9. {
  10.     class Simple_Loops
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             BigInteger n0 = BigInteger.Parse(Console.ReadLine());
  15.             BigInteger n1 = BigInteger.Parse(Console.ReadLine());
  16.             BigInteger n2 = BigInteger.Parse(Console.ReadLine());
  17.             BigInteger next = 0;
  18.             int N = int.Parse(Console.ReadLine());
  19.                 for (int i = 0; i < N - 3; i++)
  20.                 {
  21.                    next = n0 + n1 + n2;
  22.                    n0 = n1;
  23.                    n1 = n2;
  24.                    n2 = next;
  25.                 }
  26.             if (N == 1) Console.WriteLine(n0);
  27.             else if (N == 2) Console.WriteLine(n1);
  28.             else if (N == 3) Console.WriteLine(n2);
  29.             else Console.WriteLine(next);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement