Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Define palprime(n)=
- Prgm
- :Local t,pal,num,len,i,add
- :If n<6 Then
- : Disp {2,3,5,7,11}[n]
- :Else
- : t:=5
- : len:=2
- : pal:={0,1}
- : num:=101
- : Loop
- : If primetest(num) Then
- : t:=t+1
- : If t=n Then
- : Disp num
- : Stop
- : EndIf
- : EndIf
- : For i,1,len
- : If pal[i]≠9 Then
- : pal[i]:=1+pal[i]
- : If i=len Then
- : add:=2*(10^(len+i-2)+10^(len-i))
- : pal[i]:=1+pal[i]
- : num:=num+add
- : If pal[i]=5 Then
- : pal[i]:=7
- : num:=num+add
- : EndIf
- : ElseIf i=1 Then
- : num:=num+10^(len-1)
- : Else
- : num:=num+10^(len+i-2)+10^(len-i)
- : EndIf
- : Exit
- : Else
- : pal[i]:=0
- : If i>1 Then
- : num:=num-9*(10^(len+i-2)+10^(len-i))
- : Else
- : num:=num-9*10^(len-1)
- : EndIf
- : EndIf
- : EndFor
- : If num=0 Then
- : num:=10^(2*len)+1
- : len:=len+1
- : pal[len]:=1
- : EndIf
- : EndLoop
- :EndIf
- :EndPrgm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement