Zigzag and
zagzig numbers are positive integers whose digits strictly alternate between decreasing and increasing.
If the first step, from the first to the second digit is a decrease, then it is a zigzag number.
An example is 5372957391.
Similarly a zagzig number is when the first step from the first to the second digit is an increase, e.g.3729573.
Find the smallest number of digits, d, for which both conditions are true:
* a unique d-digit zeroless zigzag prime whose square is a zeroless zigzag
and also
*a unique d-digit zeroless zagzig prime whose square is a zeroless zigzag
And also find the two primes and their squares.
Note that d=2 almost works, except that the squares are zagzigs:
19^2 = 361
43^2 = 1849
p=primes(100000);
for pNo=1:length(p)
pr=p(pNo);
if pr>10
if zig(pr)
sq=pr^2;
if zig(sq)
fprintf('%7d %10d zigzag zigzag\n',[pr sq])
end
end
end
if pr>10
if zag(pr)
sq=pr^2;
if zig(sq)
fprintf('%7d %10d zagzig zigzag\n',[pr sq])
end
end
end
end
function tval=zig(n)
v1=num2str(n);
tval=true;
for i=2:2:length(v1)
if v1(i)>=v1(i-1)
tval=false;
end
if i<length(v1)
if v1(i)>=v1(i+1)
tval=false;
end
end
end
end
function tval=zag(n)
v1=num2str(n);
tval=true;
for i=2:2:length(v1)
if v1(i)<=v1(i-1)
tval=false;
end
end
if i<length(v1)
if v1(i)<=v1(i+1)
tval=false;
end
end
end
finds that for d=2
23^2 = 529 and 79^2 = 6241 are both of type zagzig zigzag, while
71^2 = 5041 is of type zigzag zigzag
but the zero in 5041 keeps it from being zeroless.
But d=3 finds
293^2 = 85849 zagzig zigzag
313^2 = 97969 zigzag zigzag
n n^2
23 529 zagzig zigzag
71 5041 zigzag zigzag
79 6241 zagzig zigzag
101 10201 zigzag zigzag
103 10609 zigzag zigzag
293 85849 zagzig zigzag
313 97969 zigzag zigzag
571 326041 zagzig zigzag
659 434281 zigzag zigzag
739 546121 zigzag zigzag
1447 2093809 zagzig zigzag
1801 3243601 zagzig zigzag
9041 81739681 zigzag zigzag
9091 82646281 zigzag zigzag
10103 102070609 zigzag zigzag
10303 106151809 zigzag zigzag
14563 212080969 zagzig zigzag
20101 404050201 zigzag zigzag
20201 408080401 zigzag zigzag
20327 413186929 zigzag zigzag
26687 712195969 zagzig zigzag
27197 739676809 zagzig zigzag
30103 906190609 zigzag zigzag
30403 924342409 zigzag zigzag
30649 939361201 zigzag zigzag
30937 957097969 zigzag zigzag
54869 3010607161 zigzag zigzag
63419 4021969561 zigzag zigzag
63929 4086917041 zigzag zigzag
71329 5087826241 zigzag zigzag
71909 5170904281 zigzag zigzag
78571 6173402041 zagzig zigzag
80329 6452748241 zigzag zigzag
86959 7561867681 zigzag zigzag
97829 9570513241 zigzag zigzag
98929 9786947041 zigzag zigzag
|
Posted by Charlie
on 2025-05-08 13:48:10 |