某岛

… : "…アッカリ~ン . .. . " .. .
July 11, 2015

Project Euler 430. Range flips


https://projecteuler.net/problem=430
期望线性性,递推数列


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);
}