Primes which contain only one odd digit: Difference between revisions

(Added XPL0 example.)
Line 111:
809 821 823 827 829 863 881 883 887
</pre>
 
=={{header|Nim}}==
<lang Nim>import sequtils, strutils
 
func isPrime(n: Positive): bool =
if n == 1: return false
if n mod 3 == 0: return n == 3
var d = 5
while d * d <= n:
if n mod d == 0:
return false
inc d, 2
if n mod d == 0:
return false
inc d, 4
result = true
 
func hasLastDigitOdd(n: Natural): bool =
var n = n
n = n div 10
while n != 0:
if (n mod 10 and 1) != 0: return false
n = n div 10
result = true
 
iterator primesOneOdd(lim: Positive): int =
var n = 1
while n <= lim:
if n.hasLastDigitOdd and n.isPrime:
yield n
inc n, 2
 
 
let list = toSeq(primesOneOdd(1000))
echo "Found $# primes with only one odd digit below 1000:".format(list.len)
for i, n in list:
stdout.write ($n).align(3), if (i + 1) mod 9 == 0: '\n' else: ' '
 
var count = 0
for _ in primesOneOdd(100_000_000):
inc count
echo "\nFound $# primes with only one odd digit below 1_000_000.".format(count)</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 1_000_000.</pre>
 
=={{header|Raku}}==
Anonymous user