Smarandache prime-digital sequence: Difference between revisions
Content added Content deleted
(Smarandache prime-digital sequence en Yabasic) |
(Added XPL0 example.) |
||
Line 2,121: | Line 2,121: | ||
The 1,000th SPDS prime is 3273527 |
The 1,000th SPDS prime is 3273527 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func IsPrime(N); \Return 'true' if N is prime |
|||
int N, I; |
|||
[if N <= 2 then return N = 2; |
|||
if (N&1) = 0 then \even >2\ return false; |
|||
for I:= 3 to sqrt(N) do |
|||
[if rem(N/I) = 0 then return false; |
|||
I:= I+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
func PrimeDigits(N); \Return 'true' if all digits are prime |
|||
int N; |
|||
[repeat N:= N/10; |
|||
case rem(0) of |
|||
0, 1, 4, 6, 8, 9: return false |
|||
other []; |
|||
until N = 0; |
|||
return true; |
|||
]; |
|||
int C, N; |
|||
[C:= 0; N:= 2; |
|||
loop [if IsPrime(N) then |
|||
if PrimeDigits(N) then |
|||
[C:= C+1; |
|||
if C <= 25 then |
|||
[IntOut(0, N); ChOut(0, ^ )]; |
|||
if C = 100 then |
|||
[Text(0, "^m^j100th: "); IntOut(0, N)]; |
|||
if C = 1000 then quit; |
|||
]; |
|||
N:= N+1; |
|||
]; |
|||
Text(0, "^m^j1000th: "); IntOut(0, N); CrLf(0); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
2 3 5 7 23 37 53 73 223 227 233 257 277 337 353 373 523 557 577 727 733 757 773 2237 2273 |
|||
100th: 33223 |
|||
1000th: 3273527 |
|||
</pre> |
</pre> |
||