Jump to content

Pierpont primes: Difference between revisions

fixed FreeBasic
m (→‎{{header|Quackery}}: added commentary)
(fixed FreeBasic)
Line 930:
 
=={{header|FreeBASIC}}==
{{output?}}
<lang freebasic>#define NPP 50
 
Function isPrime(Byval n As Ulongint) As Boolean
function is_prime( n as ulongint ) as boolean
ifIf n < 2 thenThen returnReturn false
ifIf n = 2 thenThen returnReturn true
ifIf n modMod 2 = 0 thenThen returnReturn false
forFor i asAs uintegerUinteger = 3 toTo intInt(sqrSqr(n))+1 stepStep 2
ifIf n modMod i = 0 thenThen returnReturn false
nextNext i
returnReturn true
End Function
end function
 
functionFunction is_23( byvalByval n as uintegerAs Uinteger) asAs booleanBoolean
whileWhile n modMod 2 = 0
n = n /= 2
wendWend
whileWhile n modMod 3 = 0
n = n /= 3
wendWend
ifReturn Iif(n = 1 then return, true else return, false)
End Function
end function
 
Function isPierpont(n As Uinteger) As Uinteger
function is_pierpont( n as uinteger ) as uinteger
ifIf notNot is_primeisPrime(n) thenThen returnReturn 0 'not prime
dimDim asAs integerUinteger p1 = is_23(n+1), p2 = is_23(n-1)
ifIf p1 andAnd p2 thenThen returnReturn 3 'pierpont prime of both kinds
ifIf p1 thenThen returnReturn 1 'pierpont prime of the 1st kind
ifIf p2 thenThen returnReturn 2 'pierpont prime of the 2nd kind
returnReturn 0 'prime, but not pierpont
End Function
end function
 
dimDim asAs uintegerUinteger pier(1 toTo 2, 1 toTo NPP), np(1 toTo 2) = {0, 0}, x = 1, j
Dim As Uinteger x = 1, j
whileWhile np(1) <= NPP orOr np(2) <= NPP
x = x + 1
jx += is_pierpont(x)1
if j>0 then= isPierpont(x)
ifIf j mod 2 = 1> then0 Then
If j Mod 2 = 1 Then
np(1) += 1
ifIf np(1) <= NPP thenThen pier(1, np(1)) = x
endEnd ifIf
ifIf j > 1 thenThen
np(2) += 1
ifIf np(2) <= NPP thenThen pier(2, np(2)) = x
endEnd ifIf
endEnd ifIf
Wend
wend
 
printPrint " First 50 Pierpoint primes of the first Secondkind:"
forFor j = 1 toTo NPP
printPrint j,Using pier(1," j),########"; pier(2, j);
If j Mod 10 = 0 Then Print
next j</lang>
Next j
Print !"\nFirst 50 Pierpoint primes of the secod kind:"
For j = 1 To NPP
Print Using " ########"; pier(1, j);
If j Mod 10 = 0 Then Print
Next j
next j</lang>
{{out}}
<pre>
First 50 Pierpont primes of the first kind:
2 3 5 7 13 17 19 37 73 97
109 163 193 257 433 487 577 769 1153 1297
1459 2593 2917 3457 3889 10369 12289 17497 18433 39367
52489 65537 139969 147457 209953 331777 472393 629857 746497 786433
839809 995329 1179649 1492993 1769473 1990657 2654209 5038849 5308417 8503057
 
First 50 Pierpont primes of the second kind:
2 3 5 7 11 17 23 31 47 53
71 107 127 191 383 431 647 863 971 1151
2591 4373 6143 6911 8191 8747 13121 15551 23327 27647
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087
</pre>
 
=={{header|Go}}==
2,133

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.