From ec0014e9833f135ea4d586134e4680082c8aa564 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sun, 7 Nov 2021 23:47:15 +0100 Subject: Problem 684 --- problem684.ijs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 problem684.ijs diff --git a/problem684.ijs b/problem684.ijs new file mode 100644 index 0000000..5ebca10 --- /dev/null +++ b/problem684.ijs @@ -0,0 +1,36 @@ +modn =: 1000000007 + +bigmodpower =: {{ + NB. perform the calculation b^e mod m + NB. Based on this https://en.wikipedia.org/wiki/Modular_exponentiation + 'base exp mod' =. y + + result =. 1 + base =. mod|base + while. exp > 0 do. + if. 2|exp do. + result =. mod|result*base + end. + base =. mod|*:base + exp =. <.exp%2 + end. + result +}} + +S =: {{ + t =. <.y%9 + k =. 9|y + pow =. bigmodpower 10;t;modn + r =. (pow*6+k++/>:i.k)-k+6+9*t + modn|r +}} + +fib =: {{ + if. y < 2 do. + y + else. + (fib y-2)+(fib y-1) + end. +}} M. + +problem684 =: modn|+/S@fib"0 x:2+i.89 -- cgit v1.2.3