Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Prime-decomposition/S-BASIC/prime-decomposition.basic
Normal file
43
Task/Prime-decomposition/S-BASIC/prime-decomposition.basic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
rem - return p mod q
|
||||
function mod(p, q = integer) = integer
|
||||
end = p - q * (p/q)
|
||||
|
||||
dim integer factors(16) rem log2(maxint) is sufficiently large
|
||||
|
||||
comment
|
||||
Find the prime factors of n and store in global array factors
|
||||
(arrays cannot be passed as parameters) and return the number
|
||||
found. If n is prime, it will be stored as the only factor.
|
||||
end
|
||||
function primefactors(n = integer) = integer
|
||||
var p, count = integer
|
||||
p = 2
|
||||
count = 1
|
||||
while n >= (p * p) do
|
||||
begin
|
||||
if mod(n, p) = 0 then
|
||||
begin
|
||||
factors(count) = p
|
||||
count = count + 1
|
||||
n = n / p
|
||||
end
|
||||
else
|
||||
p = p + 1
|
||||
end
|
||||
factors(count) = n
|
||||
end = count
|
||||
|
||||
rem -- exercise the routine by checking odd numbers from 77 to 99
|
||||
|
||||
var i, k, nfound = integer
|
||||
|
||||
for i = 77 to 99 step 2
|
||||
nfound = primefactors(i)
|
||||
print i;"; ";
|
||||
for k = 1 to nfound
|
||||
print factors(k);
|
||||
next k
|
||||
print
|
||||
next i
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue