только в первом цикле? С 6.8 млн справляется. Сколько раз встречается более длинный ww[] ?
я расщепил и посчитал отдельно. Очень не хотелось мне с двумя вилками(2p и 4p) возиться, но решил, что надо попробовать. Удалось и сошлось. Правда процедуру так и не сделал, а сделал 6 циклов:
Код:
{print(); tz0=getwalltime();
v0=[0, 6, 12, 30, 42, 72, 90, 96, 120, 126, 132, 156, 162, 180, 210, 222,226,240, 246, 252];
print();print(v0);print();
vco = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 46, 819, 9513, 86961, 666700, 3879368, 161926
26, 49107041, 111348972, 191311822, 247761038, 239234341, 170780294, 89844745, 3
4830936, 9970388, 2131036, 333276, 32863, 1374, 0];
forprime(pfin = 43, 43, \\ precprime(precprime(v0[#v0]/2)-1),
tz1=getwalltime();
pn=nextprime(pfin+1);
cg=vector(#vco);
v=[0,6,12,30,42,72,90,96,120,126,132, 156, 162, 180, 210, 222,226, 240, 246, 2*pn, 252];
o=1;
while(v0[o]+2*pn < v0[#v0],
if(o<>11, v[#v-1]=v0[o]+2*pn;
a=setminus(vector(v[#v]/2,i,i*2),Set(v));
ww=vector(v[#v]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<24, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
", time cg : ",strtime(getwalltime()-tz1)," memory: ", wk);
);
);
for(ll=1,#cg-1,cg[ll+1]+=vc[ll]);
print();print();
);o++);
v=[0,6,12,30,42,72,90,96,120,126,132, 156, 162, 180, 210, 222,226, 240, 246, 2*pn, 252];
o=#v0;
while(v0[o]-2*pn > v0[1],
if(o<>17,v[#v-1]=v0[o]-2*pn;
a=setminus(vector(v[#v]/2,i,i*2),Set(v));
ww=vector(v[#v]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<24, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
", time cg : ",strtime(getwalltime()-tz1)," memory: ", wk);
);
);
for(ll=1,#cg-1,cg[ll+1]+=vc[ll]);
print();print();
);o--);
v=[0,6,12,30,42,72,90,96,120,126,132, 156, 162, 180, 210, 222,226, 240, 246, 4*pn, 252];
o=1;
while(v0[o]+4*pn < v0[#v0],
v[#v-1]=v0[o]+4*pn;
a=setminus(vector(v[#v]/2,i,i*2),Set(v));
ww=vector(v[#v]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<24, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
", time cg : ",strtime(getwalltime()-tz1)," memory: ", wk);
);
);
for(ll=1,#cg-1,cg[ll+1]+=vc[ll]);
print();print();
o++;);
v=[0,6,12,30,42,72,90,96,120,126,132, 156, 162, 180, 210, 222,226, 240, 246, 4*pn, 252];
o=#v0;
while(v0[o]-4*pn > v0[1],
v[#v-1]=v0[o]-4*pn;
a=setminus(vector(v[#v]/2,i,i*2),Set(v));
ww=vector(v[#v]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<24, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
", time cg : ",strtime(getwalltime()-tz1)," memory: ", wk);
);
);
for(ll=1,#cg-1,cg[ll+1]+=vc[ll]);
print();print();
o--;);
print();print(#cg," cg = ",cg, " ",vecsum(cg));
print();
print("time: ",strtime(getwalltime()-tz1));
print();print();
print(); tz2=getwalltime();
g2=vector(#vco+1);
do=setminus(vector((v0[#v0]-2-2*pn)/2,i,i*2),Set(v0));
do=setminus(Set(do),Set(vector(#v0,i,v0[#v0+1-i]-2*pn)));
print();
print(#do," do = ",do);
\\print(#ddo," ddo = ",ddo);
print();
for(o=1,#do,
v=[0,6,12,30,42,72,90,96,120,126, 132, 156, 162, 180, 210, 222,226, 240, 246, 252, 2, 2+2*pn];
v[#v-1]=do[o];
v[#v ]=do[o]+2*pn;
a=setminus(vector(v[#v-2]/2,i,i*2),Set(v));
ww=vector(v[#v-2]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<23, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
" time g2 : ",strtime(getwalltime()-tz2)," memory: ", wk);
);
);
for(ll=1,#g2-2,g2[ll+2]+=vc[ll]);
print();print();
);
do=setminus(vector((v0[#v0]-4-4*pn)/2,i,i*2),Set(v0));
do=setminus(Set(do),Set(vector(#v0,i,v0[#v0+1-i]-4*pn)));
print();
print(#do," do = ",do);
\\print(#ddo," ddo = ",ddo);
print();
for(o=1,#do,
v=[0,6,12,30,42,72,90,96,120,126, 132, 156, 162, 180, 210, 222,226, 240, 246, 252, 2, 2+4*pn];
v[#v-1]=do[o];
v[#v ]=do[o]+4*pn;
a=setminus(vector(v[#v-2]/2,i,i*2),Set(v));
ww=vector(v[#v-2]/2,i,Map()); mapput(ww[#ww],2^#a-1,1);
vc=vector(#ww);
forprime(p=2, pfin,
wk=sum(k=1,#ww,#ww[k]);
m=setminus(vector(p,i,i-1),Set(-v%p));
am=vecextract(vector(p-1,i,fromdigits(Vecrev(apply(t->(t+i)%p>0,a)),2)),m);
for(k=1,#ww,
rr=Map();
foreach(ww[k],m,
b=m[1][1]; qq=m[1][2]; qn=0;
if(p==pfin, foreach(am,x, vc[hammingweight(bitand(x,b))+1]+=qq; ); next; );
foreach(am,x,
y=bitand(x,b);
if(y==b, qn+=qq; next);
hy=hammingweight(y)+1; nn=0;
\\if(hy<23, next);
if(mapisdefined(ww[hy],y,&nn), nn+=qq , nn=qq);
mapput(ww[hy],y,nn);
);
if(qn>0, mapput(rr,b,qn); );
);
ww[k]=rr;
);
vcmax=#vc; while(vcmax>1&&vc[vcmax]==0, vcmax--);
\\print();print("vcmax = ",vcmax);print();
if(p==pfin, print("o = ",o," --> ",nextprime(p+1),"# : ",strjoin(vc[1..vcmax],", "),", sum = ",vecsum(vc),
" time g2 : ",strtime(getwalltime()-tz2)," memory: ", wk);
);
);
for(ll=1,#g2-2,g2[ll+2]+=vc[ll]);
print();print();
);
print();print(#g2," g2 = ",g2, " ",vecsum(g2));
print();
print("time: ",strtime(getwalltime()-tz2));
print();
rp = pn-#v0+2;
for(i=1,#vco-1,
vc[i] =
(rp-i)*vco[i] + i*vco[i+1]
+ cg[i] - cg[i+1]
+ g2[i] - 2* g2[i+1] + g2[i+2]);
vc = vc[1..#vco];vco = vc;
print();
print("vc --> ",pn,"# : ",vc[1..31]," ",vecsum(vc));
print();
print();
print("time: ",strtime(getwalltime()-tz0));
print();
print();
);
print();
}quit;