English
Source / code snippets

Primzahltest and Primfaktorenzerlegung through Wheel-method

 

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 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/30/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.405 Views

Untitledvor 0 min.
Erhard Wirth06/14/24
p.specht11/20/21
Uwe Lang11/20/21
Manfred Barei11/19/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie