` ``Delvar L1 2->C 2->L1(C Input "X: ",X For(A,3,X^.5,2 For(B,3,A^.5,2 If 0=fPart(A/B Goto 0 End A->L1(C C+1->C End Goto 1 Lbl 0 A^.5->B End End Lbl 1 This generates a list of primes below the square root of X. 2->Y .5->Z For(A,2,dim(L1) Y+(1-Z)(L1(A)^2-L1(A-1)^2)->Y This multiplies this chance with the amount of numbers between the squares of the primes, and adds this to the result of the chance multiplied by the amount of numbers between the squares of the previous two primes. Z+(1-Z)/L1(A->Z This calculates the chance of a number in between the squares of two primes being prime. End Y+(1-Z)(X-L1(dim(L1))^2)->Y This adds the remainder of X minus the square of the highest prime lower than the square root of X, multiplied by the chance of numbers in this remainder being prime. Disp "Pi(X)=",Y`

This program gives okay estimates at low numbers, but for a higher X it seriously strikes out, and I can't figure out why. So in the end I'm wondering wether the code I posted does something else then I want it to do or wether the assumptions I made were wrong.

Thanks in advance, and please do ask if I need to elaborate on anything.

]]>` ``Delvar L1 2->C 2->L1(C Input "X: ",X For(A,3,X^.5,2 For(B,3,A^.5,2 If 0=fPart(A/B Goto 0 End A->L1(C C+1->C End Goto 1 Lbl 0 A^.5->B End End Lbl 1 This generates a list of primes below the square root of X. For(A,L1(dim(L1))+2,7919^2-1,2 For(B,3,A^.5,2 If 0=fPart(A/B Goto 2 End A->L1(C 7919^2-1->A End Goto 3 Lbl 2 A^.5->B End End Lbl 3 This adds the first prime greater than X to the list. 2->Y .5->Z For(A,2,dim(L1)-1 Z+(1-Z)/L1(A->Z This calculates the chance of a number in between the squares of two primes being prime. Y+(1-Z)(L1(A)^2-L1(A-1)^2)->Y This multiplies this chance with the amount of numbers between the squares of the primes, and adds this to the result of the chance multiplied by the amount of numbers between the squares of the previous two primes. End Y+(1-(Z+(1-Z)/L1(dim(L1))))(X-L1(dim(L1)-1)^2)->Y This adds the remainder of X minus the square of the highest prime lower than the square root of 10, multiplied by the chance of numbers in this remainder being prime. Disp "Pi(X)=",Y`