I spent some time yesterday writing the solution for this challenge published on Reddit, and was able to get through it without cheating, but I was left with a couple of que
if you want more bits computed per bpp call
then you have to change your equation from 1/(16^k)
base to bigger one. You can do it by summing 2
iterations (k
and k+1
) so you have something like
(...)/16^k + (...)/16^(k+1)
(...)/256^k
but in this case you need more precise int
operations. It is usually faster to use the less precise iterations
if you look at the basic equation then you see you do not need bigint
for computation at all
that is why this iterations are used but the output number is bigint
of course. So you do not need to compute modular arithmetics on bigint
.
I do not know how optimized are the one you used ... but here are mine:
if you want just speed and not infinite precision then use other PSLQ equations
My understanding of PSLQ is that it is algorithm to find relation between real number and integer iterations.
here is my favorite up to 800 digits of Pi algorithm and here is extracted code from it in case the link broke down:
//The following 160 character C program, written by Dik T. Winter at CWI, computes pi to 800 decimal digits.
int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}