30 lines
638 B
Text
30 lines
638 B
Text
func IsPrime(N); \Return 'true' if N is a prime number
|
|
int N, I;
|
|
[if N <= 1 then return false;
|
|
for I:= 2 to sqrt(N) do
|
|
if rem(N/I) = 0 then return false;
|
|
return true;
|
|
];
|
|
|
|
func SumDigits(N); \Return the sum of the digits in N
|
|
int N, Sum;
|
|
[Sum:= 0;
|
|
repeat N:= N/10;
|
|
Sum:= Sum + rem(0);
|
|
until N=0;
|
|
return Sum;
|
|
];
|
|
|
|
int Count, N;
|
|
[Count:= 0;
|
|
for N:= 0 to 500-1 do
|
|
if IsPrime(N) & IsPrime(SumDigits(N)) then
|
|
[IntOut(0, N);
|
|
Count:= Count+1;
|
|
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
|
|
];
|
|
CrLf(0);
|
|
IntOut(0, Count);
|
|
Text(0, " additive primes found below 500.
|
|
");
|
|
]
|