Primes whose first and last number is 3: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 10: | Line 10: | ||
Find and show only the ''number'' of these types of primes that are '''< 1,000,000'''. |
Find and show only the ''number'' of these types of primes that are '''< 1,000,000'''. |
||
<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 |
|||
V lim = 1'000'000 |
|||
V primes3x3 = [3] |
|||
V m = 100 |
|||
V count = 1 |
|||
L m * 3 < lim |
|||
L(n) (3 * m + 3 .. 4 * m - 7).step(10) |
|||
I n > lim |
|||
L.break |
|||
I is_prime(n) |
|||
count++ |
|||
I n < 4000 |
|||
primes3x3.append(n) |
|||
m *= 10 |
|||
print(‘Found ’primes3x3.len‘ primes starting and ending with 3 below 4000:’) |
|||
L(n) primes3x3 |
|||
print(‘#4’.format(n), end' I (L.index + 1) % 11 == 0 {"\n"} E ‘ ’) |
|||
print("\nFound "count‘ primes starting and ending with 3 below 1000000.’)</lang> |
|||
{{out}} |
|||
<pre> |
|||
Found 33 primes starting and ending with 3 below 4000: |
|||
3 313 353 373 383 3023 3083 3163 3203 3253 3313 |
|||
3323 3343 3373 3413 3433 3463 3533 3583 3593 3613 3623 |
|||
3643 3673 3733 3793 3803 3823 3833 3853 3863 3923 3943 |
|||
Found 2251 primes starting and ending with 3 below 1000000. |
|||
</pre> |
|||
=={{header|Action!}}== |
=={{header|Action!}}== |