Reputation: 337
How can I write a C++ code and which library I can use to compute and plot the sum of divisors or some similar arithmetic functions for large integers, for example integers bigger than 10^100 000.
For example the code I wrote in Mathematica:
g[n_] := Product[Prime[i], {i, 1, PrimePi[n]}];
k[999990]=g[237179]*g[661]*267064515689275851355624017992790*223092870*30030*44100*30*1296*512;
k[999991]=g[237173]*g[661]*23768741896345550770650537601358310*200560490130*30030*44100*30*7776*256;
k[999992]=g[237179]*g[661]*3217644767340672907899084554130*6469693230*30030*44100*30*7776*256;
k[999993]=g[237173]*g[673]*267064515689275851355624017992790*6469693230*30030*44100*900*1296*256;
k[999994]=g[237163]*g[677]*23768741896345550770650537601358310*200560490130*30030*44100*30*7776*256;
k[999995]=g[237179]*g[659]*23768741896345550770650537601358310*6469693230*30030*44100*30*1296*256;
ds[n_] := DivisorSigma[1, n]; %sum of divisors
f1[n_] := EulerPhi[n]; %number of coprimes less than n
d[n_] := DivisorSigma[0, n]; %number of divisors
f[n_] := DivisorSigma[1, n]/(n*Log[n]]);
sp[n_] := Sum[1/Prime[i], {i, 1, n}];
I use Mathematica 8 to compute and plot them, but it takes too long time such as one day or more. Is there any code in C++ to compute and sum of divisors for large numbers very fast.
I use windows 7 64 bit. I have downloaded Dev C++, codeblocks, and Microsoft Visual C++ 2008 Express Edition. I asked someone and he told me to use GMP(The GNU Multiple Precision Arithmetic Library). but I don't know how to use it as well.!
Actually I need the plots like the following(lines connecting points) not smooth graphs like sin or cos.
thanks
Upvotes: 0
Views: 668
Reputation: 2967
Use GMP library http://gmplib.org/ for all these kind of heavy computation. It uses big int to store such big values
Upvotes: 1