English
Source / code snippets

near Multiplikatoren a number find Primzahl

 

Jörg
Sellmeyer
with folgendem code can The Multiplikatoren a number find, which on the next lying. with z. B. 20 are the then 5 and 4.
at the same time can The function yet as Primzahlidentifizierer using.
Proc IsInt

    Parameters f!
    Return (f! - Int(f!) = 0)

ENDPROC

Proc NaheMultiplikatoren

    Parameters Wert&[],Zahl&
    Declare f1&,f2&,f!,f1!
    f! = SQrt(Zahl&)
    Case Zahl& = 0:Return 0

    If IsInt(f!)

        Wert&[0] = f!
        Wert&[1] = f!

    Else

        WhileLoop 0,Int(f!)

            f1& = Int(f!) - &Loop
            f1! = Zahl& / f1&

            If IsInt(f1!)

                Wert&[0] = f1&
                Wert&[1] = Zahl& / f1&
                Break

            EndIf

        Wend

    EndIf

    Return f!

ENDPROC

Cls
Declare Test&[2],ZufallsZahl&
Randomize
Print "bitte Button or Mausklick"

While 1

    WaitInput
    Cls
    ZufallsZahl& = Rnd(10000000)
    NaheMultiplikatoren(Test&[],ZufallsZahl&)
    Print "Nahe Multiplikatoren sind",Test&[0],"*",Test&[1],"=",ZufallsZahl&
    Print
    Print ZufallsZahl&,"ist",If(Test&[0] = 1,"","k");"eine Primzahl"

Wend

 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
05/18/18  
 




p.specht

Hab´s something weiterentwickelt to a Primzahlenfinder on FLOAT-Base...
Window Title "Zufallsprimzahlengenerator"
'(D)demonstration 2018-05 by P.woodpecker/Wien, after a idea of Jörg Sellmeyer

proc frac :parameters x!:var s!=(x!>0)-(x!<0):x!=abs(x!)

    x!=x!-round(x!,0):case x!<0:x!=1+x!:return s!*x!

endproc

proc intf :parameters x!

    var s!=(x!>0)-(x!<0)
    x!=abs(x!)
    x!=x!-frac(x!)
    return s!*x!

endproc

Proc IsIntf

    Parameters f!
    Return (f! - Intf(f!) = 0)

ENDPROC

Proc NaheMultiplikatoren

    Parameters worth![],number!
    Declare a!,f_0!,f_1!
    f_0! = Sqrt(number!)
    Case number!=0:Return 0

    If IsIntf(f_0!)

        worth![0] = f_0!
        worth![1] = f_0!

    Else

        WhileLoop 0,Intf(f_0!)

            a! = Intf(f_0!) - &Loop
            f_1! = number! / a!

            If IsIntf(f_1!)

                worth![0] = a!
                worth![1] = number! / a!
                Break

            EndIf

        Endwhile

    EndIf

    Return f_0!

ENDPROC

Cls
Declare Test![1],ZufallsZahl!
Randomize:set("decimals",1)

While 1

    ZufallsZahl! = intf(10000000.00000*Rnd()+rnd())
    NaheMultiplikatoren(Test![],ZufallsZahl!)

    If (Test![0]=1.0) and (Test![1]>1.0)

        cls
        Print "\n near-Multiplikatoren:",Test![0],"*",Test![1],"=",ZufallsZahl!
        '   If (Test![0]=1.0) and (Test![1]>1)
        font 2
        print "\n These Zufallszahl is a Primzahl!"
        sound 60,16
        font 0
        waitinput 1000

    Endif

Endwhile

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/19/18  
 




Jörg
Sellmeyer
there would I Yes sooner Doubles Quadint (meant I naturally!) as Übergabeparameter take.
And if it only around the Primzahlen goes, can the Yes yet very speed, if one 0 zurückgibt, when the first Multiplikant <> 1 found is.
 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
05/20/18  
 




p.specht

is correct, thanks! be but yet on XProfan-11, were on The Full Version of X4. Ausserdem runs The Loop dzt. only with Integers. Wenn´s with Float too long lasts, should one on Inline-Assembler sheer. your idea is super!
 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/20/18  
 




Jörg
Sellmeyer
and one can naturally vornedran too another Sieb install, in the any numbers hängenbleiben, The through 2,3,5,7,11,13,17,23,... primzahl&& divisible are and a worth > 1 yield.
 
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
05/20/18  
 




p.specht

..and Mersenne-Primzahlen works... there there Formeln. I need but real Zufallsprimeln for RSA, there can it quiet something longer last
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/20/18  
 




Jörg
Sellmeyer
the Sieb is Yes only, around the process To speed, because numbers faster rausgeworfen go, The no Primzahlen are.

means:
If (Eingang&& \ Prim&&) > 1

    Print "kann no Primzahl sein"
    return 0

ElseIf (Eingang&& \ NaechstePrim&&) > 1

    ...

EndIf

 
XProfan X3
Windows XP SP2 XProfan X4
... und hier mal was ganz anderes als Profan ...
05/20/18  
 




p.specht

everything clear.
so, be then again on Paules PC-Forum / XProfan to find...
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/20/18  
 



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

9.182 Views

Untitledvor 0 min.
Matzbub01/26/24
Stringray01/05/22
p.specht11/18/21
Roland Schäffer11/18/21
More...

Themeninformationen

this Topic has 2 subscriber:

p.specht (4x)
Jörg Sellmeyer (4x)


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