zh_stoqnov

Tribonacci

Oct 31st, 2014
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace Tribonacci
  5. {
  6. class Tribonacci
  7. {
  8. public static void Main(string[] args)
  9. {
  10. BigInteger tnMinus3 = BigInteger.Parse(Console.ReadLine());
  11. BigInteger tnMinus2 = BigInteger.Parse(Console.ReadLine());
  12. BigInteger tnMinus1 = BigInteger.Parse(Console.ReadLine());
  13. BigInteger n = BigInteger.Parse(Console.ReadLine());
  14. BigInteger tn = 0;
  15. for(int i = 4; i <= n; i++)
  16. {
  17. tn = tnMinus1 + tnMinus2 + tnMinus3;
  18. tnMinus3 = tnMinus2;
  19. tnMinus2 = tnMinus1;
  20. tnMinus1 = tn;
  21. }
  22. if (n == 3)
  23. {
  24. Console.WriteLine(tnMinus1);
  25. }
  26. else
  27. {
  28. Console.WriteLine(tn);
  29. }
  30.  
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment