Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
(add FreeBASIC) |
(Added solution for Action!) |
||
Line 8: | Line 8: | ||
Show on this page only the <u>count</u> of those primes under '''1,000,000''' which when expressed in decimal contains only one odd digit. |
Show on this page only the <u>count</u> of those primes under '''1,000,000''' which when expressed in decimal contains only one odd digit. |
||
<br><br> |
<br><br> |
||
=={{header|Action!}}== |
|||
{{libheader|Action! Sieve of Eratosthenes}} |
|||
<lang Action!>INCLUDE "H6:SIEVE.ACT" |
|||
BYTE FUNC OddDigitsCount(INT x) |
|||
BYTE c,d |
|||
c=0 |
|||
WHILE x#0 |
|||
DO |
|||
d=x MOD 10 |
|||
IF (d&1)=1 THEN |
|||
c==+1 |
|||
FI |
|||
x==/10 |
|||
OD |
|||
RETURN (c) |
|||
PROC Main() |
|||
DEFINE MAX="999" |
|||
BYTE ARRAY primes(MAX+1) |
|||
INT i,count=[0] |
|||
Put(125) PutE() ;clear the screen |
|||
Sieve(primes,MAX+1) |
|||
FOR i=2 TO MAX |
|||
DO |
|||
IF primes(i)=1 AND OddDigitsCount(i)=1 THEN |
|||
PrintI(i) Put(32) |
|||
count==+1 |
|||
FI |
|||
OD |
|||
PrintF("%E%EThere are %I primes",count) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Primes_which_contain_only_one_odd_digit.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
3 5 7 23 29 41 43 47 61 67 83 89 223 227 229 241 263 269 281 283 401 409 421 443 |
|||
449 461 463 467 487 601 607 641 643 647 661 683 809 821 823 827 829 863 881 883 887 |
|||
There are 45 primes |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |