In the window of my pocket calculator, I can see a six-figure number, abcdef
, with distinct digits between 1 and 9. A close inspection of the digits reveals that abcdef
, and def
are all prime numbers.
If I turn the calculator upside-down, I see that uvwxyz and wxyz are also prime numbers.
Which number is displayed in the window of my pocket calculator and what is the upside-down version of it?
Full credit for this problem goes to Ajit Athle who has very kindly given his permission for the puzzle to be posted here.
(In reply to Solution (spoiler)
20 while N<999999
55 for I=1 to len(Ns)-1
56 if instr(mid(Ns,I+1,*),mid(Ns,I))>0 then Good=0
60 for I=1 to len(Ns)
70 if instr("0347",mid(Ns,I,1))>0 then Good=0
71 C=mid(Ns,I,1):if C="6" then C="9":else if C="9" then C="6"
91 P3=val(Bkwd):if prmdiv(P3)<>P3 then Good=0
94 P4=val(mid(Bkwd,3,*)):if prmdiv(P4)<>P4 then Good=0
100 if Good=1 and prmdiv(P1)=P1 and prmdiv(P2)=P2 then print N;P1;P2;prmdiv(P3);prmdiv(P4):Ct=Ct+1
158269 8269 269 692851 2851
I could have used nested ifs and premature exits from loops, but UBASIC's structure makes that not worth the bother just to get an answer in a fraction of a second rather than 2 seconds.
Posted by Charlie
on 2006-12-15 11:15:45