Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
40
Task/Cuban-primes/FutureBasic/cuban-primes.basic
Normal file
40
Task/Cuban-primes/FutureBasic/cuban-primes.basic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
BBOOL local fn IsPrime( p as UInt64 )
|
||||
if ( p < 2 ) then return NO
|
||||
if ( p % 2 == 0 ) then return ( p == 2 )
|
||||
UInt64 limit = fn sqrt( (double)p )
|
||||
for UInt64 i = 3 to limit step 2
|
||||
if ( p % i == 0 ) then return NO
|
||||
next
|
||||
end fn = YES
|
||||
|
||||
local fn CubanPrimes( howMany as NSUInteger )
|
||||
CFMutableArrayRef cubanPrimes = fn MutableArrayNew
|
||||
UInt64 n = 1
|
||||
|
||||
while ( fn ArrayCount( cubanPrimes ) < howMany )
|
||||
UInt64 p = 3 * n * n + 3 * n + 1
|
||||
if ( fn IsPrime( p ) )
|
||||
MutableArrayAddObject( cubanPrimes, @(p) )
|
||||
end if
|
||||
n++
|
||||
wend
|
||||
|
||||
printf @"\nFirst 200 Cuban primes:\n"
|
||||
for NSUInteger i = 0 to fn ArrayCount( cubanPrimes ) - 1
|
||||
printf @"%7lu\b", fn NumberUnsignedLongValue( cubanPrimes[i] )
|
||||
if ( i < fn ArrayCount( cubanPrimes ) - 1 )
|
||||
if ( i % 8 == 7 )
|
||||
print
|
||||
else
|
||||
print @"\t"
|
||||
end if
|
||||
end if
|
||||
next
|
||||
print
|
||||
end fn
|
||||
|
||||
window 1, @"cuban Primes", ( 0, 0, 630, 440 )
|
||||
|
||||
fn CubanPrimes( 200 )
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue