Jump to content

Wagstaff primes: Difference between revisions

Wagstaff primes in BASIC-256
(Wagstaff primes in FreeBASIC)
(Wagstaff primes in BASIC-256)
Line 82:
10: 43: 2932031007403
</pre>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="BASIC256">function isPrime(v)
if v < 2 then return False
if v mod 2 = 0 then return v = 2
if v mod 3 = 0 then return v = 3
d = 5
while d * d <= v
if v mod d = 0 then return False else d += 2
end while
return True
end function
 
subroutine Wagstaff(num)
pri = 1
wcount = 0
wag = 0
while wcount < num
pri += 2
if isPrime(pri) then
wag = (2 ^ pri + 1) / 3
if isPrime(wag) then
wcount += 1
print rjust(wcount,2); ": "; rjust(pri,2); " => "; int(wag)
end if
end if
end while
end subroutine
 
call Wagstaff(9) #BASIC-256 does not allow larger numbers
end</syntaxhighlight>
 
=={{header|C++}}==
2,161

edits

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