John Henrry Newman
1 纽曼-康韦数
纽曼-康韦数(Newman Conway Number)序列是生成以下整数序列的序列。
1 1 2 2 3 4 4 4 5 6 7 7…
在数学上,纽曼-康韦数的序列P(n)由递推关系定义:
(1) P(n)=P(P(n-1))+P(n-P(n-1))
(2) P(1)=1, P(2)=1
计算结果:
2 文本格式源程序
using System;
namespace Legalsoft.Truffer.Algorithm
{
public static partial class Number_Sequence
{
public static int Newman_Conway_Number(int n)
{
if (n == 1 || n == 2)
{
return 1;
}
else
{
int a = Newman_Conway_Number(n - 1);
int b = Newman_Conway_Number(a);
int c = Newman_Conway_Number(n - a);
return (b + c);
}
}
public static int Newman_Conway_Number_Second(int n)
{
int[] dump = new int[n + 1];
dump[0] = 0;
dump[1] = 1;
dump[2] = 1;
for (int i = 3; i <= n; i++)
{
dump[i] = dump[dump[i - 1]] + dump[i - dump[i - 1]];
}
return dump[n];
}
}
}
——————————————————————————
POWER BY 315SOFT.COM
TRUFFER.CN
3 代码格式
using System;
namespace Legalsoft.Truffer.Algorithm
{
public static partial class Number_Sequence
{
public static int Newman_Conway_Number(int n)
{
if (n == 1 || n == 2)
{
return 1;
}
else
{
int a = Newman_Conway_Number(n - 1);
int b = Newman_Conway_Number(a);
int c = Newman_Conway_Number(n - a);
return (b + c);
}
}
public static int Newman_Conway_Number_Second(int n)
{
int[] dump = new int[n + 1];
dump[0] = 0;
dump[1] = 1;
dump[2] = 1;
for (int i = 3; i <= n; i++)
{
dump[i] = dump[dump[i - 1]] + dump[i - dump[i - 1]];
}
return dump[n];
}
}
}