Guest User

Untitled

a guest
Oct 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Numerics;
  4.  
  5. namespace no_1914
  6. {
  7. class Program
  8. {
  9. static StringBuilder strb = new StringBuilder();
  10. static void Main(string[] args)
  11. {
  12. var lineNum = Convert.ToInt32(Console.ReadLine());
  13. strb.AppendLine(((BigInteger)(Math.Pow(2, lineNum) - 1)).ToString());
  14. if(lineNum <= 20)
  15. {
  16. Hanoi(lineNum, 1, 2, 3);
  17. }
  18.  
  19. Console.Write(strb.ToString());
  20. }
  21. static void Hanoi(int num, int from, int by, int to)
  22. {
  23. if(num == 1)
  24. {
  25. strb.AppendLine(string.Format("{0} {1}", from, to));
  26. }
  27. else
  28. {
  29. Hanoi(num - 1, from, to, by);
  30. strb.AppendLine(string.Format("{0} {1}", from, to));
  31. Hanoi(num - 1, by, from, to);
  32. }
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment