## Re: A very slow algorithm from my theorem

Expand Messages
• Robin Garcia wrote: Robin Garcia wrote: Would anybody try to speed up the algorith implemented in a simple
Message 1 of 7 , Dec 2, 2004

Robin Garcia <sopadeajo2001@...> wrote: Would anybody try to speed up the algorith implemented in a simple Ubasic program?

5 n=10^3:clr time
10 for x=18 to n step 2
20 a=x\4:b=x\2:z=0
30 for i=1 to a
40 for j=i to b-i
50 for k=i+1 to (x-i-j)\2
60 if i^2+j^2=k^2+(x-i-j-k)^2 z=z+1
65 if z>0 cancel for,for,for:goto 85
70 next k:next j:next i
80 if z=0 c=c+1:print x\2;"es primo"
85 next x
86 print time;prm(c+4)
90 end

---------------------------------

Sometimes we can speed-up things.

1 word 2:n=168:b=ceil(3*n*log(n)):dim A(b):for j=1 to b:A(j)=j^2:next j
2 y=0:clr time
5 for l=1 to b
10 h=2*l+1:z=0:if h@3=0 and h<>3 or h@5=0 and h<>5 goto 90
20 s=3*h-1:t=s+2:e=isqrt(3*h):f=(h+3-2*e)\2
30 for i=h to h+f step 2:c=A(i)+A(s-i)
50 for k=i+6 to i+e step 2
60 if c=A(k)+A(t-k) :z=z+1
65 if z>0 cancel for,for:goto 90 'los compuestos quedan excluidos
70 next k:next i
80 if z=0 y=y+1:print h;"es primo";prm(y+1)
85 if y+1>=n cancel for:goto 95
90 next l
95 print y+1;"enesimo primo=";prm(y+1);time
100 end

I will invite to a bottle of Rioja wine to the first person who will improve that.

And 2 bottles to Mike if he finds out what theorems I used.

---------------------------------

---------------------------------

[Non-text portions of this message have been removed]
Your message has been successfully submitted and would be delivered to recipients shortly.