Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Pernicious-numbers/BASIC256/pernicious-numbers.basic
Normal file
46
Task/Pernicious-numbers/BASIC256/pernicious-numbers.basic
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
n = 1
|
||||
cont = 0
|
||||
print "The following are the first 25 pernicious numbers:"
|
||||
print
|
||||
|
||||
do
|
||||
if isPernicious(n) then
|
||||
print rjust(string(n), 3);
|
||||
cont += 1
|
||||
end if
|
||||
n += 1
|
||||
until cont = 25
|
||||
|
||||
print : print
|
||||
print "The pernicious numbers between 888,888,877 and 888,888,888 inclusive are:"
|
||||
print
|
||||
for n = 888888877 to 888888888
|
||||
if isPernicious(n) then print rjust(string(n), 10);
|
||||
next n
|
||||
end
|
||||
|
||||
function SumBinaryDigits(number)
|
||||
if number < 0 then number = -number # convert negative numbers to positive
|
||||
sum = 0
|
||||
while number > 0
|
||||
sum += number mod 2
|
||||
number /= 2
|
||||
end while
|
||||
return sum
|
||||
end function
|
||||
|
||||
function isPrime(v)
|
||||
if v < 2 then return False
|
||||
if v mod 2 = 0 then return v = 2
|
||||
if v mod 3 = 0 then return v = 3
|
||||
d = 5
|
||||
while d * d <= v
|
||||
if v mod d = 0 then return False else d += 2
|
||||
end while
|
||||
return True
|
||||
end function
|
||||
|
||||
function isPernicious(number)
|
||||
popcont = SumBinaryDigits(number)
|
||||
return isPrime(popcont)
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue