Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) m (Small fix of Nim solution) |
Alextretyak (talk | contribs) (Added 11l) |
||
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|11l}}== |
|||
{{trans|Nim}} |
|||
<lang 11l>F is_prime(n) |
|||
I n == 2 |
|||
R 1B |
|||
I n < 2 | n % 2 == 0 |
|||
R 0B |
|||
L(i) (3 .. Int(sqrt(n))).step(2) |
|||
I n % i == 0 |
|||
R 0B |
|||
R 1B |
|||
F hasLastDigitOdd(=n) |
|||
n I/= 10 |
|||
L n != 0 |
|||
I ((n % 10) [&] 1) != 0 |
|||
R 0B |
|||
n I/= 10 |
|||
R 1B |
|||
V l = (1.<1000).step(2).filter(n -> hasLastDigitOdd(n) & is_prime(n)) |
|||
print(‘Found ’l.len‘ primes with only one odd digit below 1000:’) |
|||
L(n) l |
|||
V i = L.index |
|||
print(‘#3’.format(n), end' I (i + 1) % 9 == 0 {"\n"} E ‘ ’) |
|||
V count = 0 |
|||
L(n) (1.<1'000'000).step(2) |
|||
I hasLastDigitOdd(n) & is_prime(n) |
|||
count++ |
|||
print("\nFound "count‘ primes with only one odd digit below 1000000.’)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Found 45 primes with only one odd digit below 1000: |
|||
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 |
|||
Found 2560 primes with only one odd digit below 1000000. |
|||
</pre> |
|||
=={{header|Action!}}== |
=={{header|Action!}}== |