Nice primes: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 1,664:
32: 983 -> Σ = 2
33: 997 -> Σ = 7
</pre>
 
=={{header|XPL0}}==
<lang XPL0>func IntLen(N); \Return number of digits in N
int N, I;
for I:= 1 to 10 do
[N:= N/10;
if N = 0 then return I;
];
 
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 SumDigits(N); \Return sum of digits in N
int N, Sum;
[Sum:= 0;
repeat N:= N/10;
Sum:= Sum + rem(0);
until N=0;
return Sum;
];
 
int C, N, SumN;
[C:= 0;
for N:= 501 to 999 do
if IsPrime(N) then
[SumN:= N;
repeat SumN:= SumDigits(SumN);
until IntLen(SumN) = 1;
if IsPrime(SumN) then
[IntOut(0, N);
C:= C+1;
if rem (C/10) then ChOut(0, ^ ) else CrLf(0);
];
];
]</lang>
 
{{out}}
<pre>
509 547 563 569 587 599 601 617 619 641
653 659 673 677 691 709 727 743 761 797
821 839 853 857 887 907 911 929 941 947
977 983 997
</pre>
772

edits