@@ -0,0 +1,1050 @@
+# A solution to the British Informatics Olympiad 2011 Question 3%0A# Scores 24/24%0Afrom __future__ import print_function%0A%0Atry:%0A%09input = raw_input%0Aexcept:%0A%09pass%0A%0Adef number_with_n_digits(n):%0A%09return 9**(n//2)%0A%0Adef nth_with_n_digits(number_of_digits, n):%0A%09if number_of_digits == 0:%0A%09%09return %22%22%0A%09if number_of_digits %25 2 == 1:%0A%09%09even = nth_with_n_digits(number_of_digits - 1, n)%0A%09%09middle = len(even)//2%0A%09%09return even%5B:middle%5D + %225%22 + even%5Bmiddle:%5D%0A%09%0A%09# 9**(n / 2)%0A%09output = %22%22%0A%09# it needs to start at 0%0A%09n -= 1%0A%09for i in range(number_of_digits // 2):%0A%09%09n, inner = divmod(n, 9)%0A%09%09inner += 1%0A%09%09#n += 1%0A%09%09output = str(inner) + output + str(10-inner)%0A%09%0A%09return output%0A%0Anth = int(input())%0A#nth = 11%0Asum_so_far = 0%0Anumber_of_digits = 0%0Awhile sum_so_far %3C nth:%0A%09number_of_digits += 1%0A%09sum_so_far += number_with_n_digits(number_of_digits)%0A%0A#print(%22The number has %25i digits!%22 %25 number_of_digits)%0A#print(nth - sum_so_far + number_with_n_digits(number_of_digits))%0Aprint(nth_with_n_digits(number_of_digits, nth - sum_so_far + number_with_n_digits(number_of_digits)))%0A%0A%0A

Add 2011 Q3