Question: Formula For Generating Prime Number Sequence Kills Plot

#Could you check how to generate a correct plot? I use Sum here because nested add commands didn't work.

restart;
S := proc (x) options operator, arrow; 1+Sum(floor((x/(Sum(floor(cos(Pi*(factorial(n-1)+1)/n)^2), n = 1 .. r)))^(1/x)), r = 1 .. 2^x) end proc;

#This yields the Prime number sequence, try seq(value(S(x)), x = 1 .. 7);

#Problem:

# Plot seems wrong:
plot(S(x), x = 1 .. 7);

#Raising Digits >15 results in empty plots

Please Wait...