| |
|
|
p.specht
| Please not confuse with the general factors- or. Kofaktoren-investigation all Teiler a number: here go only Primzahlen extract!
Window Title "Primfaktorisierung and Primtest with the Wheel-Methode"
'Q: https://en.wikipedia.org/wiki/Wheel_factorization
Cls:font 2:appendmenubar 100,"Zahl < 2147483647 , 0 = Test, -1 = Ende"
declare v&,factors&[],k&,i&,in$,n&,plus&[8],checked!
'Init: the always same wheel for a 3it-Wheel:
plus&[1]=4:plus&[2]=2:plus&[3]=4:plus&[4]=2
plus&[5]=4:plus&[6]=6:plus&[7]=2:plus&[8]=6
Repeat
input:
print " number = ";:input in$
if val(in $)>2147483647:cls:goto "Eingabe":endif
n&=val(in $):case n&=-1:End
case n&=0:n&=223092870
FactorWheel(abs(n&))
ShowOutput
until 0
Proc FactorWheel :parameters n&
clear factors&[]:case n&<1:return:declare k&,i&,v&
' example 3it-Wheel:
:whilenot n& mod 2:inc v&:factors&[v&]=2:n&=n&\2:Endwhile
:whilenot n& mod 3:inc v&:factors&[v&]=3:n&=n&\3:Endwhile
:whilenot n& mod 5:inc v&:factors&[v&]=5:n&=n&\5:Endwhile
k&=7:i&=1
while sqr(k&)<=n&
ifnot n& mod k&:inc v&:factors&[v&]=k&:n&=n&\k&
else:k&=k&+plus&[i&]:if i&<8:inc i&:else:i&=1:endif
endif
Endwhile: inc v&:factors&[v&]=n&
Endproc
Proc ShowOutput :case n&<1:return:print " ";n&;" = ";
var s&=sizeof(factors&[])-1:s&=s&-(factors&[s&]=1)
Whileloop s&:print factors&[&Loop];
case &Loop<s&:print " ";chr $(215);" ";
case %pos>54:print "\n ";
endwhile : case factors&[s&]=n&:print " (prim!)";
if %csrlin>20:waitinput:cls:endif:print
Endproc
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/30/21 ▲ |
|
|
|