Motzkin numbers: Difference between revisions

Added C# version, arbitrary precision
(Upgraded to 'full' task, plenty of examples, no controversy.)
(Added C# version, arbitrary precision)
Line 122:
41 192,137,918,101,841,817
</pre>
 
=={{header|C#|CSharp}}==
Arbitrary precision.
<lang csharp>using System;
using BI = System.Numerics.BigInteger;
 
class Program {
 
// has multiple factors (other than 1 and x)
static bool hmf(BI x) {
if (x < 2) return true;
if ((x & 1) == 0) return x > 2;
if ( x % 3 == 0) return x > 3;
int l = (int)Math.Sqrt((double)x);
for (int j = 5, d = 4; j <= l; j += d = 6 - d)
if (x % j == 0) return x > j;
return false;
}
 
static void Main(string[] args) {
BI a = 0, b = 1, t;
int n = 1, s = 0, d = 1, c = 0, f = 1;
while (n <= 60)
Console.WriteLine ("{0,34:n0} {1}",
t = b / n++,
hmf(t) ? "" : "is prime.",
t = b,
b = ((c += d * 3 + 3) * a +
(f += d * 2 + 3) * b) /
(s += d += 2),
a = t);
}
}</lang>
{{out}}
<pre> 1
1
2 is prime.
4
9
21
51
127 is prime.
323
835
2,188
5,798
15,511 is prime.
41,835
113,634
310,572
853,467
2,356,779
6,536,382
18,199,284
50,852,019
142,547,559
400,763,223
1,129,760,415
3,192,727,797
9,043,402,501
25,669,818,476
73,007,772,802
208,023,278,209
593,742,784,829
1,697,385,471,211
4,859,761,676,391
13,933,569,346,707
40,002,464,776,083
114,988,706,524,270
330,931,069,469,828
953,467,954,114,363 is prime.
2,750,016,719,520,991
7,939,655,757,745,265
22,944,749,046,030,949
66,368,199,913,921,497
192,137,918,101,841,817
556,704,809,728,838,604
1,614,282,136,160,911,722
4,684,478,925,507,420,069
13,603,677,110,519,480,289
39,532,221,379,621,112,004
114,956,499,435,014,161,638
334,496,473,194,459,009,429
973,899,740,488,107,474,693
2,837,208,756,709,314,025,578
8,270,140,811,590,103,129,028
24,119,587,499,879,368,045,581
70,380,687,801,729,972,163,737
205,473,381,836,953,330,090,977
600,161,698,382,141,668,958,313
1,753,816,895,177,229,449,263,803
5,127,391,665,653,918,424,581,931
14,996,791,899,280,244,858,336,604
43,881,711,243,248,048,262,611,670 </pre>
 
=={{header|F_Sharp|F#}}==