Calmo numbers: Difference between revisions
Content added Content deleted
(Added C) |
(Initial FutureBasic task solution added) |
||
Line 391: | Line 391: | ||
715 [5, 11, 13, 55, 65, 143] [29, 263] |
715 [5, 11, 13, 55, 65, 143] [29, 263] |
||
957 [3, 11, 29, 33, 87, 319] [43, 439] |
957 [3, 11, 29, 33, 87, 319] [43, 439] |
||
</pre> |
|||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
local fn IsPrime( n as NSUInteger ) as BOOL |
|||
BOOL isPrime = YES |
|||
NSUInteger i |
|||
if n < 2 then exit fn = NO |
|||
if n = 2 then exit fn = YES |
|||
if n mod 2 == 0 then exit fn = NO |
|||
for i = 3 to int(n^.5) step 2 |
|||
if n mod i == 0 then exit fn = NO |
|||
next |
|||
end fn = isPrime |
|||
local fn IsCalmo( n as NSUInteger ) as BOOL |
|||
BOOL isCalmo = YES |
|||
double limit = sqr(n) |
|||
NSUInteger count = 0, sumd = 0, sumq = 0, k = 0, q = 0, d = 2 |
|||
while ( d < limit ) |
|||
q = n/d |
|||
if ( n mod d == 0 ) |
|||
count++ : sumd += d : sumq += q |
|||
if ( count == 3 ) |
|||
k += 3 |
|||
if fn IsPrime( sumd ) == NO then exit fn = NO |
|||
if fn IsPrime( sumq ) == NO then exit fn = NO |
|||
count = 0 : sumd = 0 : sumq = 0 |
|||
end if |
|||
end if |
|||
d++ |
|||
wend |
|||
if count != 0 or k == 0 then exit fn = NO |
|||
end fn = isCalmo |
|||
NSUInteger n |
|||
for n = 1 to 1000 -1 |
|||
if fn IsCalmo( n ) then print n; " "; |
|||
next |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
165 273 385 399 561 595 665 715 957 |
|||
</pre> |
</pre> |
||