Project Euler 430. Range flips


https://projecteuler.net/problem=503
期望線性性,遞推數列


int main(){

    LL n = 1e10, m = 4000; DB z = 0;

    FOR_1(i, 1, n){
        DB p = (2.*i*(n+1-i)-1)/((DB)n*n);
        DB t = 1.-2*p;
        if (sgn(t, 0.99) <= 0){
            z += (n-2*(i-1))/2;
            break;
        }
        z += (1.+pow(t, m));
    }

    OT(z);
}