Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
42
Task/Wieferich-primes/PureBasic/wieferich-primes.basic
Normal file
42
Task/Wieferich-primes/PureBasic/wieferich-primes.basic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
Procedure.i isPrime(n)
|
||||
Protected k
|
||||
|
||||
If n = 2 : ProcedureReturn #True
|
||||
ElseIf n <= 1 Or n % 2 = 0 : ProcedureReturn #False
|
||||
Else
|
||||
For k = 3 To Int(Sqr(n)) Step 2
|
||||
If n % k = 0
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
Next
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
Procedure.i isWeiferich(p)
|
||||
Protected q, p2
|
||||
|
||||
If Not isPrime(p) : ProcedureReturn #False : EndIf
|
||||
q = 1
|
||||
p2 = Pow(p, 2)
|
||||
While p > 1
|
||||
q = (2*q) % p2
|
||||
p - 1
|
||||
Wend
|
||||
If q = 1
|
||||
ProcedureReturn #True
|
||||
Else
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
OpenConsole()
|
||||
PrintN("Wieferich primes less than 5000: ")
|
||||
For i = 2 To 5000
|
||||
If isWeiferich(i)
|
||||
PrintN(Str(i))
|
||||
EndIf
|
||||
Next i
|
||||
Input()
|
||||
CloseConsole()
|
||||
Loading…
Add table
Add a link
Reference in a new issue