login
A068880
Smallest n-digit square with property that digits alternate in parity.
2
1, 16, 121, 1296, 12321, 147456, 1038361, 10929636, 103652761, 1010985616, 10327234129, 101070583056, 1010163694761, 10107210905856, 101030903296569, 1012923810743296, 10101430507492129, 101034169694343076, 1010167692929438121, 10101478149656965696
OFFSET
1,2
LINKS
Sean A. Irvine, Table of n, a(n) for n = 1..53 (terms 1..33 from Giovanni Resta)
EXAMPLE
a(4) = 1296 as 1, 2, 9 and 6 have odd and even parity alternately.
MATHEMATICA
altQ[n_] := n < 10 || Union[ Total /@ Partition[ Mod[ IntegerDigits@n, 2], 2, 1]] == {1}; a[n_] := Block[{r = Ceiling@ Sqrt@ FromDigits[ Mod[Range@ n, 2]]}, While[! altQ[r^2], r++]; r^2]; Array[a, 16] (* Giovanni Resta, Aug 17 2018 *)
PROG
(Python)
from math import isqrt
from itertools import count, islice
def allalt(s):
es, os, e, o = set(s[::2]), set(s[1::2]), set("02468"), set("13579")
return (es <= o and os <= e) or (es <= e and os <= o)
def a(n):
r = isqrt(int(("10"*n)[:n]))
while len(s:=str(r*r)) < n or not allalt(s): r += 1
return int(s)
print([a(n) for n in range(1, 21)]) # Michael S. Branicky, Mar 21 2024
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Amarnath Murthy, Mar 19 2002
EXTENSIONS
More terms from Sascha Kurz, Mar 23 2002
a(14)-a(20) from Giovanni Resta, Aug 17 2018
STATUS
approved