1 ! Copyright (c) 2023 Cecilia Knaebchen.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: combinators kernel locals math math.functions
7 ! https://projecteuler.net/problem=463
12 ! The function f is defined for all positive integers as
18 ! f(4n+1) = 2f(2n+1) - f(n)
19 ! f(4n+3) = 3f(2n+1) - 2f(n)
21 ! The function S(n) is defined as Σ_{i=1}^n f(i)
23 ! S(8) = 22 and S(100) = 3604
25 ! Find S(3^37). Give the last 9 digits of your answer.
32 ! S(n) = S([n/2]) + 2S([(n+1)/2]) + 3S([(n-1)/2]) -
33 ! 2S([(n+1)/4]) - 4S([(n-1)/4]) - 2S([(n-3)/4]) - 1
46 n 3 - 4 /i S 2 * - 1 -
50 : euler463 ( -- answer )
51 3 37 ^ S 1000000000 mod ;