#C/bc, <s>233</s> <s>121</s> 112 bytes (assuming 3 byte penalty for `|bc`) 1. Inspired by Cole Cameron, removed the hacky character manipulation and just do arithmetic on the argument value. 2. Changed to scanf from using arg vector. C[10]={1},n=1,k,t;main(){for(scanf("%d",&k);k--;)for(t=k;t;t/=10)printf("%d/%d*",++n,++C[t%10]);puts("1");} Needs `bc` to actually do the arbitrary precision computation. Ungolfed and warning free: #include <stdio.h> int main() { int C[10]={1},n=1,k,t; /* 0 is special-cased */ for(scanf("%d",&k);k--;) /* For each integer less than k */ for(int t=k;t;t/=10) /* For each digit in t */ printf("%d/%d*",++n,++C[t%10]); /* Incremental choice computation */ puts("1"); /* Finish the expression */ } Illustrated (which I trust shows the algorithm): $ for i in {0..15} 100 ; do printf %4d\ $i;./cg70892g<<<$i;done 0 1 1 1 2 2/1*1 3 2/1*3/1*1 4 2/1*3/1*4/1*1 5 2/1*3/1*4/1*5/1*1 6 2/1*3/1*4/1*5/1*6/1*1 7 2/1*3/1*4/1*5/1*6/1*7/1*1 8 2/1*3/1*4/1*5/1*6/1*7/1*8/1*1 9 2/1*3/1*4/1*5/1*6/1*7/1*8/1*9/1*1 10 2/1*3/1*4/1*5/1*6/1*7/1*8/1*9/1*10/1*1 11 2/1*3/2*4/1*5/1*6/1*7/1*8/1*9/1*10/1*11/1*12/2*1 12 2/1*3/2*4/3*5/2*6/1*7/1*8/1*9/1*10/1*11/1*12/1*13/1*14/4*1 13 2/1*3/1*4/2*5/3*6/4*7/2*8/1*9/1*10/1*11/1*12/1*13/1*14/1*15/2*16/5*1 14 2/1*3/1*4/2*5/1*6/3*7/4*8/5*9/2*10/1*11/1*12/1*13/1*14/1*15/1*16/2*17/2*18/6*1 15 2/1*3/1*4/2*5/1*6/3*7/1*8/4*9/5*10/6*11/2*12/1*13/1*14/1*15/1*16/1*17/2*18/2*19/2*20/7*1 100 2/1*3/2*4/3*5/1*6/4*7/1*8/5*9/1*10/6*11/1*12/7*13/1*14/8*15/1*16/9*17/1*18/10*19/1*20/11*21/2*22/2*23/12*24/3*25/4*26/5*27/2*28/6*29/2*30/7*31/2*32/8*33/2*34/9*35/2*36/10*37/2*38/11*39/2*40/12*41/3*42/3*43/13*44/4*45/13*46/5*47/6*48/7*49/3*50/8*51/3*52/9*53/3*54/10*55/3*56/11*57/3*58/12*59/3*60/13*61/4*62/4*63/14*64/5*65/14*66/6*67/14*68/7*69/8*70/9*71/4*72/10*73/4*74/11*75/4*76/12*77/4*78/13*79/4*80/14*81/5*82/5*83/15*84/6*85/15*86/7*87/15*88/8*89/15*90/9*91/10*92/11*93/5*94/12*95/5*96/13*97/5*98/14*99/5*100/15*101/6*102/6*103/16*104/7*105/16*106/8*107/16*108/9*109/16*110/10*111/16*112/11*113/12*114/13*115/6*116/14*117/6*118/15*119/6*120/16*121/7*122/7*123/17*124/8*125/17*126/9*127/17*128/10*129/17*130/11*131/17*132/12*133/17*134/13*135/14*136/15*137/7*138/16*139/7*140/17*141/8*142/8*143/18*144/9*145/18*146/10*147/18*148/11*149/18*150/12*151/18*152/13*153/18*154/14*155/18*156/15*157/16*158/17*159/8*160/18*161/9*162/9*163/19*164/10*165/19*166/11*167/19*168/12*169/19*170/13*171/19*172/14*173/19*174/15*175/19*176/16*177/19*178/17*179/18*180/19*181/10*182/20*183/20*184/20*185/20*186/20*187/20*188/20*189/20*190/20*1 And, with the pipe through bc (and adding the computation of F(1000): $ time for i in {0..15} 100 1000; do printf "%4d " $i;./cg70892g<<<$i|bc;done 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880 10 3628800 11 119750400 12 1816214400 13 43589145600 14 1111523212800 15 30169915776000 100 89331628085599251432057142025907698637261121628839475101631496666431\ 15835656928284205265561741805657733401084399630568002336920697364324\ 98970890135552420133438596044287494400000000 1000 45200893173828954313462564749564394748293201305047605660842814405721\ 30092686078003307269244907986874394907789568742409099103180981532605\ 76231293886961761709984429587680151617686667512237878219659252822955\ 55855915137324368886659115209005785474446635212359968384367827713791\ 69355041534558858979596889046036904489098979549000982849236697235269\ 84664448178907805505235469406005706911668121136625035542732996808166\ 71752374116504390483133390439301402722573240794966940354106575288336\ 39766175522867371509169655132556575711715087379432371430586196966835\ 43089966265752333684689143889508566769950374797319794056104571082582\ 53644590587856607528082987941397113655371589938050447115717559753757\ 79446152023767716192400610266474748572681254153493484293955143895453\ 81280908664541776100187003079567924365036116757255349569574010994259\ 42252682660514007543791061446917037576087844330206560326832409035999\ 90672829766080114799705907407587600120545365651997858351981479835689\ 62520355320273524791310387643586826781881487448984068291616884371091\ 27306575532308329716263827084514072165421099632713760304738427510918\ 71188533274405854336233290053390700237606793599783757546507331350892\ 88552594944038125624374807070741486495868374775574664206439929587630\ 93667017165594552704187212379733964347029984154761167646334095514093\ 41014074159155080290000223139198934433986437329522583470244030479680\ 80866686589020270883335109556978058400711868633837851169536982150682\ 22082858700246313728903459417761162785473029666917398283159071647546\ 25844593629926674983035063831472139097788160483618679674924756797415\ 01543820568689780263752397467403353950193326283322603869951030951143\ 12095550653333416019778941123095611302340896001090093514839997456409\ 66516109033654275890898159131736630979339211437991724524614375616264\ 98121300206207564613016310794402755159986115141240217861695468584757\ 07607748055900145922743960221362021598547253896628914921068009536934\ 53398462709898222067305585598129104976359039062330308062337203828230\ 98091897165418693363718603034176658552809115848560316073473467386230\ 73804128409097707239681863089355678037027073808304307450440838875460\ 15170489461680451649825579772944318869172793737462142676823872348291\ 29912605105826175323042543434860948610529385778083808434502476018689\ 05150440954486767102167489188484011917026321182516566110873814183716\ 30563399848922002627453188732598763510259863554716922484424965400444\ 85477201353937599094224594031100637903407963255597853004241634993708\ 88946719656130076918366596377038503741692563720593324564994191848547\ 42253991635763101712362557282161765775758580627861922528934708371322\ 38741942406807912441719473787691540334781785897367428903185049347013\ 44010772740694376407991152539070804262207515449370191345071234566501\ 33117923283207435702471401696679650483057129117719401161591349048379\ 16542686360084412816741479754504459158308795445295721744444794851033\ 08800000000 real 0m0.246s user 0m0.213s sys 0m0.055s This computed F(5000) -- an 18,592-digit number -- in under 10 seconds. $ time ./cg70892g3<<<5000|BC_LINE_LENGTH=0 bc|wc -c 18593 real 0m9.274s user 0m9.273s sys 0m0.005s