Almost prime: Difference between revisions
Content deleted Content added
→{{header|GW-BASIC}}: Simplified |
Not a robot (talk | contribs) Add CLU |
||
Line 907: | Line 907: | ||
nil |
nil |
||
</pre> |
</pre> |
||
=={{header|CLU}}== |
|||
<lang clu>kprime = proc (n,k: int) returns (bool) |
|||
f: int := 0 |
|||
p: int := 2 |
|||
while f<k & p*p<=n do |
|||
while n//p=0 do |
|||
n := n/p |
|||
f := f+1 |
|||
end |
|||
p := p+1 |
|||
end |
|||
if n>1 then f:=f+1 end |
|||
return(f=k) |
|||
end kprime |
|||
start_up = proc () |
|||
po: stream := stream$primary_output() |
|||
for k: int in int$from_to(1,5) do |
|||
i: int := 2 |
|||
c: int := 0 |
|||
stream$puts(po, "k = " || int$unparse(k) || ":") |
|||
while c<10 do |
|||
if kprime(i,k) then |
|||
stream$putright(po, int$unparse(i), 4) |
|||
c := c+1 |
|||
end |
|||
i := i+1 |
|||
end |
|||
stream$putl(po, "") |
|||
end |
|||
end start_up</lang> |
|||
{{out}} |
|||
<pre>k = 1: 2 3 5 7 11 13 17 19 23 29 |
|||
k = 2: 4 6 9 10 14 15 21 22 25 26 |
|||
k = 3: 8 12 18 20 27 28 30 42 44 45 |
|||
k = 4: 16 24 36 40 54 56 60 81 84 88 |
|||
k = 5: 32 48 72 80 108 112 120 162 168 176</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |