[seqfan] Re: A071901: Mmca code for large n's?

Michael Porter ic_designer at verizon.net
Wed Nov 18 00:14:53 CET 2009


Here's a PARI program that uses the digit-by-digit method to calculate the square root.  It's not very efficient - calculating the first 1000 terms takes 26 seconds.  And the prime(n) function doesn't work for n greater than about 45000.

A071901(n) = {local(r,x,d);r=floor(sqrt(prime(n)));x=100*(prime(n)-r^2);\Q
for(digits=1, n, d=0; while((20*r+d)*d <= x, d++);\Q
d--; /* while loop overshoots correct digit */\Q
x=100*(x-(20*r+d)*d); r=10*r+d); d}

I put in the \Q's at the end of each line so it comes out correct if you put it in to the sequence.  If you want to copy it from here, you'll need to remove the \Q's.

- Michael


--- On Tue, 11/17/09, zak seidov <zakseidov at yahoo.com> wrote:

From: zak seidov <zakseidov at yahoo.com>
Subject: [seqfan]  A071901: Mmca code for large n's?
To: "seqfaneu" <seqfan at seqfan.eu>
Date: Tuesday, November 17, 2009, 5:30 AM

In
A071901 n-th decimal digit of the fractional part of the square root of the n-th prime. ,

Mmca code is OK up to n=114

q[n_] := Mod[Floor[10^n*Sqrt[Prime[n]]], 10]; Table[q[n], {n, 114}]

but at n=115 (and larger n's) Mmca complains:
q[115]
Internal precision limit $MaxExtraPrecision ... reached while evaluating... 

This version happlily gives even 100000th term
in no time:
Table[rd=RealDigits[N[Sqrt[Prime[n]],2*n]];
  rd[[1,rd[[2]]+n]],{n,10000,100000,10000}]
{4,5,2,6,2,2,6,7,2,3}

Any ideas? 
C++? PARI?

Zak


      


_______________________________________________

Seqfan Mailing list - http://list.seqfan.eu/



More information about the SeqFan mailing list