staafl

problem 2 - tribonacci

Mar 30th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. long t1 = long.Parse(Console.ReadLine());
  8. long t2 = long.Parse(Console.ReadLine());
  9. long t3 = long.Parse(Console.ReadLine());
  10. long n = long.Parse(Console.ReadLine());
  11. long tn = 0;
  12. long tn_3 = t1;
  13. long tn_2 = t2;
  14. long tn_1 = t3;
  15.  
  16. for (int i = 4; i <= n; i++)
  17. {
  18. tn = tn_3 + tn_2 + tn_1;
  19. tn_3 = tn_2;
  20. tn_2 = tn_1;
  21. tn_1 = tn;
  22. }
  23. Console.WriteLine(tn);
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment