diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2021-11-08 01:41:27 +0100 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2021-11-08 01:41:27 +0100 |
commit | cbaaff8c1d3d74418368d9dc30efb83336b75d33 (patch) | |
tree | 11e5680237f46f13bfb192be462bb03cc2dda105 /problem684.ijs | |
parent | ec0014e9833f135ea4d586134e4680082c8aa564 (diff) |
Simplify 684
Diffstat (limited to 'problem684.ijs')
-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 =: {{ |