RosettaCodeData/Task/Wieferich-primes/FutureBasic/wieferich-primes.basic
2026-04-30 12:34:36 -04:00

29 lines
695 B
Text

BOOL local fn IsPrime( n as NSUInteger )
if n < 2 then exit fn = NO
if n = 2 then exit fn = YES
if n % 2 == 0 then exit fn = NO
for NSUInteger i = 3 to int(n^.5) step 2
if n % i == 0 then exit fn = NO
next
end fn = YES
BOOL local fn IsWieferichPrime( p as NSUInteger )
if ( !fn IsPrime(p) ) then return NO
NSUInteger q = 1, p2 = p^2
while ( p > 1 )
q = ( 2 * q ) % p2
p = p - 1
wend
if ( q == 1 ) then return YES else return NO
end fn = NO
void local fn FindWieferichs
printf @"Wieferich primes less than 5,000:"
for NSUInteger i = 1 to 5000
if fn IsWieferichPrime(i) then printf @"\t%lu\t\b", i
next
end fn
fn FindWieferichs
HandleEvents