RosettaCodeData/Task/Carmichael-3-strong-pseudoprimes/FutureBasic/carmichael-3-strong-pseudoprimes.basic
2025-08-11 18:05:26 -07:00

41 lines
986 B
Text

include "NSLog.incl"
int local fn SpecialMod( n as int, m as int )
return ((n % m) + m) % m
end fn = 0
BOOl local fn IsPrime( n as NSUInteger ) as BOOL
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
void local fn Carmichael3( p1 as int )
if (!fn IsPrime(p1)) then return
int h3, d, p2, p3
for h3 = 1 to p1 - 1
for d = 1 to (h3 + p1) -1
if ((h3 + p1) * (p1 - 1) % d == 0 && fn SpecialMod(-p1 * p1, h3) == d % h3)
p2 = 1 + ((p1 - 1) * (h3 + p1) / d)
if (!fn IsPrime(p2)) then continue
p3 = 1 + (p1 * p2 / h3)
if ( !fn IsPrime(p3) || (p2 * p3) % (p1 - 1) != 1 ) then continue
NSLog( @"%3d * %-5d * %-6d = %ld", p1, p2, p3, p1 * p2 * p3 )
end if
next
next
end fn
for int p1 = 2 to 61
fn Carmichael3(p1)
next
NSLogScrollToTop
HandleEvents