Motzkin numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|C#|CSharp}}: extended to 80th, added comment)
m (→‎{{header|C#|CSharp}}: added missing ordinal number suffix in comment)
Line 293: Line 293:
if (x < 4) return x == 1;
if (x < 4) return x == 1;
if ((x & 1) == 0 || x % 3 == 0) return true;
if ((x & 1) == 0 || x % 3 == 0) return true;
int l = (int)Math.Sqrt((double)x); // this limit works because the 40th to 80 Motzkin numbers have factors of 2 or 3
int l = (int)Math.Sqrt((double)x); // this limit works because the 40th to 80th Motzkin numbers have factors of 2 or 3
for (int j = 5, d = 4; j <= l; j += d = 6 - d)
for (int j = 5, d = 4; j <= l; j += d = 6 - d)
if (x % j == 0) return x > j;
if (x % j == 0) return x > j;