Project Euler_Problem 193_Few Repeated Digits_欧拉筛+容斥公式

时间:2024-04-18 19:14:58

解题思路:暴力搜索

代码:

void solve() {
    ll i, j,k,x,y,z,p,q,u,v,l,l1;
    N = 999966663333, NN = 1024;
    //N = 1000;
    double a, b, c,d;
    
    M.NT.get_prime_Euler(1000000);

    l = M.NT.pcnt;

    for (i = 1; i <= l; i++) {
        u = M.NT.prime[i];
        v = M.NT.prime[i + 1];
        x = u * u;
        y = v * v;

        if (x > N)break;

        for (j = x; j < y; j=j+u) {
            if (j > N)break;
            if (j == x)continue;
            if (j % v == 0)continue;
            ans1 = ans1 + j;
        }

        for (j = y; j > x; j = j - v) {
            if (j > N)continue;
            if (j == y)continue;
            if (j % u == 0)continue;
            ans1 = ans1 + j;
        }

    }

    printf("%lld\n",ans1);
}