MSN Home  |  My MSN  |  Hotmail
Sign in to Windows Live ID Web Search:   
go to MSNGroups 
Groups Home  |  My Groups  |  Language  |  Help  
 
Primes less than or equal to xPrimeslessthanorequaltox@groups.msn.com 
  
What's New
  Join Now
  Documents  
  Pictures  
  Links  
  primeapigcc.c  
  readfile.bas  
  writefile.bas  
  sumtwinapi.bas  
  sumtwinapi.c  
  sumprimedll.bas  
  sumtwinapi2.bas  
  readfilegcc.c  
  sumprimesGccAdd  
  
  
  Tools  
 

'The Power Basic sumprimedll.bas
#COMPILE DLL "f:\sieve\sumprimedll.dll"
#Include "WIN32API.INC"

FUNCTION PRIMEPB$(BYVAL x&&,fil as ASCIIZ) EXPORT
'returns the nth prime number < 370 bill. n < = 14 bill
DIM j AS QUAD,a AS QUAD
OPEN fil$ FOR BINARY AS 1 BASE = 0
SEEK 1,0
    j=x&&*8-8
    GET #1,j,a
CLOSE 1
    PRIMEPB = str$(a)
END FUNCTION

FUNCTION PRIMEPB2$(BYVAL x&&,fil as ASCIIZ) EXPORT
DIM j AS QUAD,a AS QUAD
OPEN fil$ FOR BINARY AS 1 BASE = 0
SEEK 1,0
    j=x&&*8-8
    GET #1,j,a
CLOSE 1
    PRIMEPB2 = str$(a)
END FUNCTION

FUNCTION SUMPRIMES$(BYVAL n&,fil as ASCIIZ) EXPORT
DIM fact AS EXT,appr AS EXT,n3 AS EXT
DIM j AS LONG,k AS LONG,y$
DIM a(999) AS QUAD
DIM s1 AS EXT,s2 AS EXT,n2 AS EXT,er AS EXT
fact = .5409
OPEN fil$ FOR BINARY AS 1 BASE = 0
SEEK 1,0
    FOR j = 0 TO n&-1
    GET #1,,a()
    for k = 0 to 999
    s1=s1+INT(a(k)/10000)
    s2 = s2 + a(k) MOD 10000
    NEXT
    NEXT
CLOSE 1
n3=n&
appr = n3*n3*LOG(n3)*fact
n2 = s1*10000+s2
er = 1.0 - n2/appr
y1$ = STR$(s1,18)+"0000"+"+"+STR$(s2,18)
y2$ ="Actual "+STR$(n2,18)
y3$ ="Approx "+STR$(appr,18)
y4$ ="Error  "+STR$(er,10)
sumprimes$ =_
y1$ + $CRLF +_
y2$ + $CRLF +_
y3$ + $CRLF +_
y4$
END FUNCTION

SUB SUMPRIMES2(BYVAL n&,fil as ASCIIZ,retrn as ASCIIZ) EXPORT
DIM fact AS EXT,appr AS EXT,n3 AS EXT
DIM j AS LONG,k AS LONG
DIM a AS QUAD
DIM s1 AS EXT,s2 AS EXT,n2 AS EXT,er AS EXT
fact = .5409
OPEN fil$ FOR BINARY AS 1 BASE = 0
SEEK 1,0
    FOR j = 0 TO n&-1
    GET #1,,a
    s1=s1+INT(a/10000)
    s2 = s2 + a MOD 10000
    NEXT
CLOSE 1
n3=n&
appr = n3*n3*LOG(n3)*fact
n2 = s1*100000+s2
er = 1.0 - n2/appr
y1$ = STR$(s1,18)+"0000"+","
y2$ = STR$(s2,18)+","
y3$ = STR$(n2,18)+","
y4$ = STR$(appr,18)+","
y5$ = STR$(er,10)+","
retrn$ = y1$ + y2$ + y3$ + y4$ + y5$
END SUB

SUB SUMPRIMES3(BYVAL n&,fil as ASCIIZ,retrn as ASCIIZ) EXPORT
DIM fact AS EXT,appr AS EXT,n3 AS EXT
DIM j AS LONG,k AS LONG
DIM a(999) AS QUAD
DIM s1 AS EXT,s2 AS EXT,n2 AS EXT,er AS EXT
fact = .5409
OPEN fil$ FOR BINARY AS 1 BASE = 0
SEEK 1,0
    FOR j = 0 TO n&-1
    GET #1,,a()
FOR k=0 TO 999
    s1=s1+INT(a(k)/10000)
    s2 = s2 + a(k) MOD 10000
    NEXT
    NEXT
CLOSE 1

n3=n&*500
appr = n3*n3*LOG(n3)*fact
n2 = s1*100000+s2
er = 1.0 - n2/appr
y1$ = STR$(s1,18)+"0000"+","
y2$ = STR$(s2,18)+","
y3$ = STR$(n2,18)+","
y4$ = STR$(appr,18)+","
y5$ = STR$(er,10)+","
retrn$ = y1$ + y2$ + y3$ + y4$ + y5$
END SUB

FUNCTION XGETB(BYVAL n&,BYVAL rl&,BYVAL a AS QUAD) EXPORT as QUAD
GET #n&,rl&,a
FUNCTION = a
END FUNCTION

FUNCTION OPENB(BYVAL n&,fil as ASCIIZ) EXPORT as long
OPEN fil$ FOR BINARY AS n& BASE = 0
END FUNCTION

FUNCTION ISPRIMEPB(BYVAL n&&) EXPORT as long
DIM  m as QUAD,x1 as QUAD,x2 as QUAD,v as QUAD,rc as QUAD
x1=0
x2=14456422318&&      'Change this from f:\hugo2\makebinfast.bas
while(x2-x1) > 1
m = (x1+x2)/2
rc=m*8
GET #1,rc,v
if v < n&&  then
x1=m
else
x2=m
end if
if v=n&& then
    FUNCTION = 1
    EXIT FUNCTION
end if
wend
FUNCTION = 0
END FUNCTION

FUNCTION PIX(BYVAL n1&&,BYVAL n2&&) EXPORT as QUAD
DIM  m as QUAD,x1 as QUAD,x2 as QUAD,v as QUAD,rc as QUAD
DIM  j as quad,c as quad
if n1&& = 1 then c=1 else c=0
for j = n1&& to n2&& step 2
x1=0
'primes in prime2-370bill.bin built by f:\hugo2\makebinfast.bas
x2=14456422318&&

while (x2-x1) > 1  'Perform binary search to find if number is prime.
m = (x1+x2)/2
rc=m*8
GET #1,rc,v
if v < j  then
x1=m
else
x2=m
end if
if v=j then
    c=c+1
end if
wend
next
FUNCTION = c
END FUNCTION
SUB SUMTWINS(BYVAL n&,fil as ASCIIZ,retrn as ASCIIZ) EXPORT
DIM j AS LONG,k AS LONG,flag&
DIM p1 AS QUAD,p2 as QUAD, primem&&
DIM s1 AS EXT,s2 AS EXT,n2 AS EXT
OPEN fil$ FOR BINARY AS 1 BASE = 0
    s1=0
    s2=0
     FOR j = 0 TO n&-1
    SEEK 1,j*8
    GET #1,,p1
    GET #1,,p2
      if p2 - p1 = 2 then
     s1 = s1+INT(p1/10000)+INT(p2/10000)
     s2 = s2 + p1 MOD 10000 + p2 MOD 10000
     flag=1
     else
     flag=0
     end if
     NEXT
 'final adjustment if necessary speeds things up greatly.
     if flag then
     s1 = s1 - INT(p1/10000) - INT(p2/10000)
     s2 = s2 -  p1 MOD 10000 - p2 MOD 10000
     end if
CLOSE 1
y1$ = STR$(s1,18)+"0000"+","
y2$ = STR$(s2,18)+","
y3$ = STR$(n2,18)+","
retrn$ = y1$ + y2$ + y3$
END SUB

SUB COUNTTWINS(BYVAL n&,fil as ASCIIZ,retrn as ASCIIZ) EXPORT
DIM j AS LONG,k AS LONG
DIM p1 AS QUAD,p2 as QUAD
DIM s1 AS QUAD
OPEN fil$ FOR BINARY AS 1 BASE = 0
    s1=0
     FOR j = 0 TO n&-1
     SEEK 1,j*8
     GET #1,,p1
    GET #1,,p2
    if p2 > n& then exit
      if p2 - p1 = 2 then
     s1 = s1+1
     end if
     NEXT
CLOSE 1
y1$ = STR$(s1,18)
retrn$ = y1$
END SUB

 

Notice: Microsoft has no responsibility for the content featured in this group. Click here for more info.
  Try MSN Internet Software for FREE!
    MSN Home  |  My MSN  |  Hotmail  |  Search
Feedback  |  Help  
  ©2005 Microsoft Corporation. All rights reserved.  Legal  Advertise  MSN Privacy