Semiprime: Difference between revisions
Content deleted Content added
→{{header|Quackery}}: bug fix |
Added PROMAL |
||
Line 2,021: | Line 2,021: | ||
6: 2 x 3 |
6: 2 x 3 |
||
semiprime form 1 to 100: 4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95 |
semiprime form 1 to 100: 4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95 |
||
</pre> |
|||
=={{header|PROMAL}}== |
|||
<syntaxhighlight lang="promal"> |
|||
;;; find some semiprimes - numbers with two prime factors |
|||
PROGRAM semiPrimes |
|||
INCLUDE library |
|||
FUNC BYTE isSemiPrime |
|||
ARG WORD n |
|||
WORD f |
|||
WORD factorCount |
|||
BYTE result |
|||
BEGIN |
|||
f = 2 |
|||
factorCount = 0 |
|||
WHILE factorCount < 3 AND n > 1 |
|||
WHILE n % f = 0 |
|||
factorCount = factorCount + 1 |
|||
n = n / f |
|||
f = f + 1 |
|||
IF factorCOunt = 2 |
|||
result = 1 |
|||
ELSE |
|||
result = 0 |
|||
RETURN result |
|||
END |
|||
WORD n |
|||
BEGIN |
|||
OUTPUT "Semiprimes under 100:#C " |
|||
FOR n = 1 TO 99 |
|||
IF isSemiPrime( n ) |
|||
OUTPUT " #W", n |
|||
OUTPUT "#CSemiprimes between 1670 and 1690:#C " |
|||
FOR n = 1670 TO 1690 |
|||
IF isSemiPrime( n ) |
|||
OUTPUT " #W", n |
|||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Semiprimes under 100: |
|||
4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95 |
|||
Semiprimes between 1670 and 1690: |
|||
1671 1673 1678 1679 1681 1685 1687 1689 |
|||
</pre> |
</pre> |
||