Ickiverar 发表于 2019-12-9 18:29:56

用于三维的c++代码,在我的电脑上单线程算到11层需要3秒。
要算更多层,只需要更改const int maxl=层数;

#include<stdint.h>
#include<stdio.h>

const int maxl=11;
int64_t in={0},on={0},out={0};
int64_t g;

#define xm(proc,x,y,z)                  \
    proc(x-2,y-2,z-2,2*x+2*y+2*z+6,0);\
    proc(x-2,y-2,z,2*x+2*y+z+6,z-2);    \
    proc(x-2,y-2,z+2,2*x+2*y+4,2*z-2);\
    proc(x-2,y,z-2,2*x+y+2*z+6,y-2);    \
    proc(x-2,y,z+2,2*x+y+4,y+2*z-4);    \
    proc(x-2,y+2,z-2,2*x+2*z+4,2*y-2);\
    proc(x-2,y+2,z,2*x+z+4,2*y+z-4);    \
    proc(x-2,y+2,z+2,2*x+2,2*y+2*z-4);

#define x0(proc,x,y,z)                  \
    proc(x,y-2,z-2,x+2*y+2*z+6,x-2);    \
    proc(x,y-2,z+2,x+2*y+4,x+2*z-4);    \
    proc(x,y+2,z-2,x+2*z+4,x+2*y-4);    \
    proc(x,y+2,z+2,x+2,x+2*y+2*z-6);   

#define xp(proc,x,y,z)                  \
    proc(x+2,y-2,z-2,2*y+2*z+4,2*x-2);\
    proc(x+2,y-2,z,2*y+z+4,2*x+z-4);    \
    proc(x+2,y-2,z+2,2*y+2,2*x+2*z-4);\
    proc(x+2,y,z-2,y+2*z+4,2*x+y-4);    \
    proc(x+2,y,z+2,y+2,2*x+y+2*z-6);    \
    proc(x+2,y+2,z-2,2*z+2,2*x+2*y-4);\
    proc(x+2,y+2,z,z+2,2*x+2*y+z-6);    \
    proc(x+2,y+2,z+2,0,2*x+2*y+2*z-6);

void ffull(int l,int64_t x,int64_t y,int64_t z,int64_t fh,int64_t fl){
    ++l;
    x*=3;
    y*=3;
    z*=3;
    fh*=9;
    fl*=9;
    int64_t nfh,nfl;
#define proc(nx,ny,nz,dfh,dfl)          \
do{                                     \
    nfh=fh-4*(dfh),nfl=fl+4*(dfl);      \
    if(nfl>=0)out+=g;                \
    else if(nfh<=0)in+=g;            \
    else {                              \
      on+=g;                     \
      if(l<maxl)                      \
            ffull(l,nx,ny,nz,nfh,nfl);\
    }                                 \
}while(0)

    xm(proc,x,y,z);
    x0(proc,x,y,z);
    xp(proc,x,y,z);

}

void fhalf(int l,int64_t y,int64_t z,int64_t fh,int64_t fl){
    const int64_t x=0;
    ++l;
    y*=3;
    z*=3;
    fh*=9;
    fl*=9;
    int64_t nfh,nfl;
#define proch(nx,ny,nz,dfh,dfl)         \
do{                                     \
    nfh=fh-4*(dfh),nfl=fl+4*(dfl);      \
    if(nfl>=0)out+=g/2;            \
    else if(nfh<=0)in+=g/2;          \
    else {                              \
      on+=g/2;                     \
      if(l<maxl)                      \
            fhalf(l,ny,nz,nfh,nfl);   \
    }                                 \
}while(0)

    x0(proch,x,y,z);
    xp(proc,x,y,z);
}

int main(){
    on=1;
    on=20;
    g=8;
    ffull(1,2,2,2,18,-6);
    g=24;
    fhalf(1,2,2,10,-6);
    for(int i=1;i<=maxl;++i){
      /*
            Note: To avoid overflow,
            in & out are not real counts of level i cubes
            unless after executing following lines :

      in+=20*in;
      out+=20*out;

            This can be done in Mathematica
      */
      printf("%llu %llu %llu\n",in,on,out);
    }
}

mathe 发表于 2019-12-9 18:53:32

我试着运行了一下,和chyang的结果不同
0 20 0
44 216 140
1440 1224 1656
8400 7968 8112
50112 54456 54792
356232 367944 364944
2458824 2444520 2455536
16239768 16284576 16366056
108395712 108525168 108770640
723385080 723469800 723648480
4823029008 4822582872 4823784120

mathe 发表于 2019-12-9 20:20:52

0 20 0
44 216 140
2320 1224 4456
54800 7968 97232
1146112 54456 1999432
23278472 367944 40353584
468028264 2444520 809527216
9376805048 16284576 16206910376
187644496672 108525168 324246978160
3753613318520 723469800 6485663211680
75077089399408 4822582872 129718088017720
1501573939443704 32150080560 2594393910475736
30031693123408792 214334797104 51888092541794104

Ickiverar 发表于 2019-12-9 23:15:40

Ickiverar 发表于 2019-12-9 18:29
用于三维的c++代码,在我的电脑上单线程算到11层需要3秒。
要算更多层,只需要更改const int maxl=层数;
...

8线程并行写完了,20秒13层,预计3天能算到18层。开算。

mathe 发表于 2019-12-10 11:45:10

能够分别计算结果关于模2^64和2^64-1的结果吗?如果这样,最后就不怕溢出,最后通过中国剩余定理可以得出更大范围的结果了。
毕竟还是指数递增的,差值好像公差接近$\frac{20}3$,18项应该没有问题,但是计算更多项就有问题了。

Ickiverar 发表于 2019-12-13 18:23:26

18层的数据
内部 球面上 外部

0 20 0
44 216 140
2320 1224 4456
54800 7968 97232
1146112 54456 1999432
23278472 367944 40353584
468028264 2444520 809527216
9376805048 16284576 16206910376
187644496672 108525168 324246978160
3753613318520 723469800 6485663211680
75077089399408 4822582872 129718088017720
1501573939443704 32150080560 2594393910475736
30031693123408792 214334797104 51888092541794104
600635291349699440 1428893539656 1037763279756760904
12012715352891236816 9525966857976 20755275121141905208
240254370564131706488 63506419362240 415105565929448931272
4805087834658423387496 423376135436184 8302111741965441176320
96101759515675744360544 2822507323770168 166042237661816931869288

mathe 发表于 2020-1-15 16:07:18

上面的数据已经更新在 https://oeis.org/A329302
页: 1 2 3 4 5 [6]
查看完整版本: 谢尔宾斯基地毯与圆的交集