43 lines
991 B
Text
43 lines
991 B
Text
local bigint = require "pluto:bigint"
|
|
local fmt = require "fmt"
|
|
|
|
local function A(k)
|
|
if k < 6 then
|
|
local x1 = 1
|
|
local x2 = -1
|
|
local x3 = -1
|
|
local x4 = 1
|
|
local c1 = {0, 0, 0, 1, 2, 3}[k + 1]
|
|
local c2 = {0, 0, 1, 1, 1, 2}[k + 1]
|
|
local c3 = {0, 1, 1, 0, 0, 1}[k + 1]
|
|
local c4 = {1, 1, 0, 0, 0, 0}[k + 1]
|
|
return bigint.new(c1 * x1 + c2 * x2 + c3 * x3 + c4 * x4)
|
|
end
|
|
local one = bigint.new(1)
|
|
local c0 = bigint.new(3)
|
|
local c1 = bigint.new(2)
|
|
local c2 = bigint.new(1)
|
|
local c3 = bigint.new(0)
|
|
for j = 5, k - 1 do
|
|
c3 += c0 - one
|
|
c0 += c1
|
|
c1 += c2
|
|
c2 += c3
|
|
end
|
|
return c0 - c1 - c2 + c3
|
|
end
|
|
|
|
local function p(k)
|
|
io.write($"A{k} = ")
|
|
local s = A(k):tostring()
|
|
if #s < 60 then
|
|
print(s)
|
|
else
|
|
fmt.print("-%s (%d digits)", fmt.abridge(s:sub(2), 5), #s - 1)
|
|
end
|
|
end
|
|
|
|
for i = 0, 39 do p(i) end
|
|
p(500)
|
|
p(10_000)
|
|
p(100_000)
|