using System; using System.Collections.Generic; using System.Text; namespace A245582 { class Program { static void Main(string[] args) { Console.WriteLine(0+" "+1); // For n == 0 for (int n = 1; true; n++) { string s; long max = (long)Math.Pow(2, n - 1); // Strings starting with 0, double the count later int cnt = 0; for (long x = 0; x < max; x++) { s = Convert.ToString(x, 2).PadLeft(n, '0'); s = s + s; if (s.HasPalindromicSubStringOfLength(n)) { cnt++; } } Console.WriteLine(n + " " + (2*cnt)); } } } unsafe static class StringExtensions { // Check all substrings of length 'len', return true if a palindromic one is found public static bool HasPalindromicSubStringOfLength(this String str, int len) { int max; max = str.Length - len + 1; fixed (char* p = str) { for (int i = 0; i < max; i++) { bool ok = true; char* p1 = p + i; char* p2 = p1 + len - 1; while (p1 < p2) { if (*p1 != *p2) { ok = false; break; } p1++; p2--; } if (ok) { return true; } } } return false; } } }