Numbers whose binary and ternary digit sums are prime: Difference between revisions

Content added Content deleted
(Added Go)
(Added XPL0 example.)
Line 1,313: Line 1,313:


Found 61 such numbers.
Found 61 such numbers.
</pre>

=={{header|XPL0}}==
<lang XPL0>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, Base); \Return sum of digits in N for Base
int N, Base, Sum;
[Sum:= 0;
repeat N:= N/Base;
Sum:= Sum + rem(0);
until N=0;
return Sum;
];

int Count, N;
[Count:= 0;
for N:= 0 to 200-1 do
if IsPrime(SumDigits(N,2)) & IsPrime(SumDigits(N,3)) 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, " such numbers found below 200.
");
]</lang>

{{out}}
<pre>
5 6 7 10 11 12 13 17 18 19
21 25 28 31 33 35 36 37 41 47
49 55 59 61 65 67 69 73 79 82
84 87 91 93 97 103 107 109 115 117
121 127 129 131 133 137 143 145 151 155
157 162 167 171 173 179 181 185 191 193
199
61 such numbers found below 200.
</pre>
</pre>