===============================
Langsam, aber sicher.
Gruss
Quellcode
- Windowtitle "Primeigenschaftsprüfung: Langsames Divisionsverfahren"
- WindowStyle 24:CLS:font 1
- declare n!,k!,pr!
- k!=2^53-1
- k!=90000103
- set("decimals",0)
- repeat
- print "\n ?: ";
- input n!
- if n!=0:n!=k!:k!=k!-1:endif
- locate %csrlin-1,25
- pr!=Primes(n!)
- casenot pr!:print n!,
- print format$(" #0 ist prim!;Negativ??;Nicht prim!",pr!)
- waitinput 42
- until %key=27
- print "\n ---":beep
- Waitinput
- End
- Proc primes :parameters n!
- declare max!,prime!,i!
- if n!=2: prime!=2
- elseif (n!<=1) or (remodf(n!,2)=0): prime!=0
- else
- prime!=n!
- i!=3:max!=sqrt(n!)
- while i!<=max!
- if remodf(n!,i!)=0
- prime!=0
- Break
- endif
- i!=i!+2
- endwhile
- endif
- return prime!
- endproc
- proc floor :parameters x!
- case abs(x!)<(10^-35):return 0
- case x!>0:return intf(x!)
- return (abs(x!-intf(x!)) < 10^-35)-intf(abs(x!-1))
- endproc
- proc remodf :parameters x!,y!
- case abs(x!)<(10^-35):return 0
- case abs(y!)<(10^-35):return x!
- return ((x!>0)-(x!<0))*abs(x!-y!*floor(x!/y!))
- endproc
- 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