Special odd numbers: Difference between revisions
Content added Content deleted
(Added C++ solution) |
(Added Forth solution) |
||
Line 170: | Line 170: | ||
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923 |
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923 |
||
933 939 943 949 951 955 959 965 973 979 985 989 993 995 |
933 939 943 949 951 955 959 965 973 979 985 989 993 995 |
||
</pre> |
|||
=={{header|Forth}}== |
|||
{{works with|Gforth}} |
|||
<lang forth>: odd-square-free-semi-prime? { n -- ? } |
|||
n 1 and 0= if false exit then |
|||
0 { count } |
|||
3 |
|||
begin |
|||
dup dup * n <= |
|||
while |
|||
begin |
|||
dup n swap mod 0= |
|||
while |
|||
count 1+ to count |
|||
count 1 > if |
|||
drop false exit |
|||
then |
|||
dup n swap / to n |
|||
repeat |
|||
2 + |
|||
repeat |
|||
drop |
|||
count 1 = ; |
|||
: special_odd_numbers ( n -- ) |
|||
." Odd square-free semiprimes < " dup 1 .r ." :" cr |
|||
0 swap |
|||
1 do |
|||
i odd-square-free-semi-prime? if |
|||
1+ |
|||
i 4 .r |
|||
dup 20 mod 0= if cr then |
|||
then |
|||
2 +loop |
|||
cr ." Count: " . cr ; |
|||
1000 special_odd_numbers |
|||
bye</lang> |
|||
{{out}} |
|||
<pre> |
|||
Odd square-free semiprimes < 1000: |
|||
15 21 33 35 39 51 55 57 65 69 77 85 87 91 93 95 111 115 119 123 |
|||
129 133 141 143 145 155 159 161 177 183 185 187 201 203 205 209 213 215 217 219 |
|||
221 235 237 247 249 253 259 265 267 287 291 295 299 301 303 305 309 319 321 323 |
|||
327 329 335 339 341 355 365 371 377 381 391 393 395 403 407 411 413 415 417 427 |
|||
437 445 447 451 453 469 471 473 481 485 489 493 497 501 505 511 515 517 519 527 |
|||
533 535 537 543 545 551 553 559 565 573 579 581 583 589 591 597 611 623 629 633 |
|||
635 649 655 667 669 671 679 681 685 687 689 695 697 699 703 707 713 717 721 723 |
|||
731 737 745 749 753 755 763 767 771 779 781 785 789 791 793 799 803 807 813 815 |
|||
817 831 835 843 849 851 865 869 871 879 889 893 895 899 901 905 913 917 921 923 |
|||
933 939 943 949 951 955 959 965 973 979 985 989 993 995 |
|||
Count: 194 |
|||
</pre> |
</pre> |
||