A068877 Largest n-digit prime with property that digits alternate in parity.
7, 89, 983, 8969, 98981, 898987, 9898921, 89898983, 989898989, 8989898969, 98989898981, 898989898987, 9898989898901, 89898989898967, 989898989898943, 8989898989898969, 98989898989898981, 898989898989898943, 9898989898989898789
Offset: 1
Examples
a(4) = 8969 as 8, 9, 6 and 9 have even and odd parity alternately.
Links
- Giovanni Resta, Table of n, a(n) for n = 1..500
Programs
-
Sage
concat = lambda x: Integer(''.join(map(str,x)),base=10) def A068877(n): dd = {0:range(0,10,2)[::-1], 1: range(1,10,2)[::-1]} for d0 in [1..9][::-1]: if n % 2 == 0 and d0 % 2 == 1: continue # optimization ds = [dd[(d0+1+i) % 2] for i in range(n-1)] for dr in cartesian_product(ds): c = concat([d0]+dr) if is_prime(c): return c # [D. S. McNeil, Apr 02 2011]
Extensions
a(15)-a(19) from Donovan Johnson, Apr 01 2011