using System;
using System.Numerics;
namespace ConsoleHannuo
{
internal class Hannuo
{
static void Main(string[] args)
{
//解法一,递归
TotalSteps answer1 = new TotalSteps();
BigInteger result1 = answer1.Step(Convert.ToInt32(Console.ReadLine()));
Console.WriteLine(result1);
//j=解法二,迭代
TotalSteps answer2 = new TotalSteps();
BigInteger result2 = (BigInteger)(answer2.Step2(Convert.ToInt32(Console.ReadLine())));
Console.WriteLine(result2);
}
}
class TotalSteps
{
//解法一,递归
public BigInteger Step(int X)
{
if (X == 1)
{
return 1;
}
else
{
var result = 1 + 2 * Step(X - 1);
return result;
}
}
解法二,迭代
public double Step
C# 汉诺塔问题,递归&迭代解法
于 2022-06-11 00:40:01 首次发布