#JavaScript (ES6) 250222 250
This can be golfed a little moreThis can be golfed a little more(done), but I like the fact that it is not limited to JS standard numbers (17 decimal digits of precision) and that it is fast.
Test running the snippet below in an EcmaScript 6 compliant browser (implementing arrow functions and the spread operator. Time is acceptable up to 9998 - IE Firefox)don't try 9999 and be patient with 999.
// functionAs Ma -complete Modulusprogram with arbitrary precision - a is aI/O stringvia ofpopup decimal digits M=for(a,b,q=1,t=0n=+prompt(a=[0],j=a.lengthq=[t=1])=>;t;){whilefor(j--c=1,t=i=0;i<a.length;i++)+a[j]a[i]=a[i]&c?t+=q:0:a[i]|c?(c=0,q=t+=q[i],1):c=0;c&&(q*10a[i]=c,t+=q[i]=q[i-1]*10%n)%b;return t%b;t%=n} // function D - Long division with arbitrary precision - a is a string of decimal digits D=.reverse(a,b,r='',z=0)=>[...a].map(a=>(z+=az+=[a],d=z/b|0n|0,z%=bz%=n,r||d?r+=d:0),r='',z=0)&&r;alert([r,a.join``]) // TestableAs functiona testable function f=n=>{ for(i=0;++i<1e7&&(z=M(v=i.toString(2)a=[0],n)q=[t=1];t;); { for(c=1,t=i=0;i<a.length;i++); return z a[i]=a[i]&c?['big']0:[Da[i]|c?(vc=0,n)t+=q[i],v] }1):c=0 c&&(a[i]=c,t+=q[i]=q[i-1]*10%n); // As a complete programt%=n with I/O} via popup P=_=>alert a.reverse(f).map(prompta=>()z+=[a],d=z/n|0,z%=n,r||d?r+=d:0)[0],r='',z=0) return [r,a.join``] } // Test and timing T=~new Date out = x => O.innerHTML += x + '\n' console.log=(...x)=>O.innerHTML+=x+'\n' setTimeout(_=>{ ;[2;[1,2,10, 21, 23, 98, 72, 9,99] 99, 999] .forEach(w=>console.log(wtest, f(w))i); => { var t0 = ~new Date console.log var result = f('Timetest) out('n='+test+' '+result+' time(ms) '+' + (Tt0-~new Date)) })},100) <pre id=O><id=O>Timing test cases ... </pre> More readable
This is the first version, with modulus and long division as separated functions.
// function M - Modulus with arbitrary precision - a is a string of decimal digits M = (a, b, q = 1, t = 0, j = a.length) => { while (j--) + a[j] ? t += q : 0, q = (q * 10) % b; return t % b } // function D - Long division with arbitrary precision - a is a string of decimal digits D = (a, b, r = '', z = 0) => [...a].map(a => (z += a, d = z / b | 0, z %= b, r || d ? r += d : 0)) && r // Testable function f = n => { for (i = 0; ++i < 1e7 && (z = M(v = i.toString(2), n));); return z ? ['big'] : [D(v, n), v] }