diff options
-rw-r--r-- | problem684.ijs | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/problem684.ijs b/problem684.ijs index 5ebca10..494c34d 100644 --- a/problem684.ijs +++ b/problem684.ijs @@ -1,28 +1,10 @@ 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 + pow10 =. 10 modn&|@^t NB. This is effective in J for calculating 10^t mod modn + (6+y)-~pow10*+/6,k,>:i.k }} fib =: {{ |