Increasing gaps between consecutive Niven numbers: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 759:
23 126 6,292,149 88,996,914
</pre>
 
 
=={{header|FutureBasic}}==
Note: Computation time rises exponentially after the first 22 iterations.
<syntaxhighlight lang="futurebasic">
local fn DigitSum( n as UInt64, sum as UInt64 ) as UInt64
sum++
while ( n > 0 and n mod 10 == 0 )
sum -= 9
n = n / 10
wend
end fn = sum
 
 
local fn IsDivisible( n as UInt64, d as UInt64 ) as BOOL
BOOL result
if ( ( d and 1 ) == 0 and ( n and 1 ) == 1 ) then result = NO : exit fn
result = n mod d == 0
end fn = result
 
local fn DoIt
UInt64 niven, previous = 1, gap = 0, sum = 0
long niven_index = 0, gap_index = 1
printf( @"Index Gap Niven index Niven number" )
printf( @"----- --- ----------- ------------" )
for niven = 1 to gap_index <= 24
sum = fn DigitSum( niven, sum )
if ( fn IsDivisible( niven, sum ) )
if ( niven > previous + gap )
gap = niven - previous
printf @"%3d %6llu %13d %15llu", gap_index, gap, niven_index, previous
gap_index++
end if
previous = niven
niven_index++
end if
next
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Index Gap Niven index Niven number
----- --- ----------- ------------
1 1 1 1
2 2 10 10
3 6 11 12
4 7 26 63
5 8 28 72
6 10 32 90
7 12 83 288
8 14 102 378
9 18 143 558
10 23 561 2889
11 32 716 3784
12 36 1118 6480
13 44 2948 19872
14 45 4194 28971
15 54 5439 38772
16 60 33494 297864
17 66 51544 478764
18 72 61588 589860
19 88 94748 989867
20 90 265336 2879865
21 99 800054 9898956
22 108 3750017 49989744
23 126 6292149 88996914
24 135 44194186 689988915
</pre>
 
 
 
 
 
 
 
717

edits