Brilliant numbers: Difference between revisions

FreeBASIC
(FreeBASIC)
Line 582:
First brilliant number >= 1000000: 1018081 at position 10538
</pre>
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
function is_prime( n as uinteger ) as boolean
if n = 2 then return true
if n<2 or n mod 2 = 0 then return false
for i as uinteger = 3 to sqr(n) step 2
if (n mod i) = 0 then return false
next i
return true
end function
 
function first_prime_factor( n as uinteger ) as uinteger
if n mod 2 = 0 then return 2
for i as uinteger = 3 to sqr(n) step 2
if (n mod i) = 0 then return i
next i
return n
end function
 
dim as uinteger count = 0, n = 0, ff, sf, expo = 0
 
while count<100
ff = first_prime_factor(n)
sf = n/ff
if is_prime(sf) and len(str(ff)) = len(str(sf)) then
print n,
count = count + 1
if count mod 6 = 0 then print
end if
n = n + 1
wend
print
count = 0
 
n = 0
do
ff = first_prime_factor(n)
sf = n/ff
if is_prime(sf) and len(str(ff)) = len(str(sf)) then
count = count + 1
if n > 10^expo then
print n;" is brilliant #"; count
expo = expo + 1
if expo = 9 then end
end if
end if
n = n + 1
loop
</syntaxhighlight>
<pre>
4 6 9 10 14 15
21 25 35 49 121 143
169 187 209 221 247 253
289 299 319 323 341 361
377 391 403 407 437 451
473 481 493 517 527 529
533 551 559 583 589 611
629 649 667 671 689 697
703 713 731 737 767 779
781 793 799 803 817 841
851 869 871 893 899 901
913 923 943 949 961 979
989 1003 1007 1027 1037 1067
1073 1079 1081 1121 1139 1147
1157 1159 1189 1207 1219 1241
1247 1261 1271 1273 1333 1343
1349 1357 1363 1369
4 is brilliant #1
14 is brilliant #5
121 is brilliant #11
1003 is brilliant #74
10201 is brilliant #242
100013 is brilliant #2505
1018081 is brilliant #10538
10000043 is brilliant #124364
</pre>
 
 
=={{header|Go}}==
{{trans|Wren}}
Line 693 ⟶ 771:
First >= 10,000,000,000,000 is 34,896,253,010 in the series: 10,000,000,000,073
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">import Control.Monad (join)
781

edits