# [dc], <s>107</s> 106 bytes 9k[0sD]sZ0dsRsK_1?ddsXsN-sM[lX5v1dsD+2/lN^dsY>ZlXlDlY*-sXlDdAlN^*lR+sRlKdlN+lD*-sKlN1-dsNlM<L]dsLxlRlKk1/p [Try it online!][TIO-k9or1p8l] [dc]: https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html [TIO-k9or1p8l]: https://tio.run/##DcmxCsIwGEXh92kI7S90EEQRsqXNkCltqQ7erXcQLhTfPmY6cD58ar0e26Cwax2grPi2B6Ci5DVvLONpUHCXnukFLfeVhYFL59WKZ7sds1NmBJNjaBCZzEOJ823aoenHpof131pt/AM "dc – Try It Online" Or [verify all the test cases][1]. [1]: https://tio.run/##RY5BC4JAFITv/oqHdEq23KBDYEZgXawNPGliYT7N6LWGLyKofrstEXSZgW8YZg45112R38C/ts2xzS/gefZis7S7yTl1Och46yJHHO7lDJFjVoLXKcXju0QOnNGQ1A458bcUU0BJX7BxnBvap8jhiEIk5VBggpCUFMiK1t4qQ149yKRnObx2Zs@yqqYFDScNTzkYyPHbAsDGCEBZ1A0IDXZPw9QH@w8NeAEWICr43f@2dNl9AA **How it works:** 9k Set precision to 9 decimal places. [0sD]sZ Macro Z, sets D to 0 when called. 0dsRsK Initialize R and K to 0, leaving 0 on the stack. ?ddsXsN Input number, store it in both X and N, _1r-sM and set M to -N-1. [ Start a macro (which will be used as a loop). lX Set X = N. 5v1dsD+2/lN^ Set D=1. Compute phi^N, dsY and store it in Y. >Z If phi^N > X, use macro Z to set D=0. lXlDlY*-sX If D is 1, set X = X - phi^N. lDdAlN^*lR+sR R += D * 10^N. This places the digit D in R in the right position, treating R as a number in base 10. lKdlN+lD*-sK If D is 1, set K = -N. (K is used as the number of "decimal" places to print.) lN1-dsN Set N = N-1, leaving the new value of N at the top of the stack. lM<L] If M < L, call macro L recursively (in other words, start another loop iteration). dsLx Save the macro in register L, and execute it. Once the loop is done: lR Load the result R. lKk Set the precision (number of decimal places) to K. 1/ Divide R by 1 to convert it to the desired precision. p Print it.