Mobius && divisible block BZOJ2301--

topic

For given n th interrogation, each seeking the number of the number of (x, y), satisfying A≤ x ≦ B, C≤ Y ≦ D, and the GCD (X, Y) = K, GCD (X, Y ) as a function of x and the greatest common divisor of y.

analysis

Mobius classic introductory questions.

(I also just learned, I write about

#include <bits / STDC ++ H.>
 the using  namespace STD; 

typedef Long  Long LL;
 const  int MAXN = 50000 + 10 ;
 int MU [MAXN], Prime [MAXN], TOT;   // Mobius table, prime number table, the number of prime numbers 
BOOL VIS [MAXN];
 int premu [MAXN];         // Mobius prefix and 

void getMu ( int n-) 
{ 
    MU [ . 1 ] = . 1 ;
     for ( int I = 2 ; I <= n-; ++ I ) 
    { 
        IF(!vis[i]) prime[++tot] = i, mu[i] = -1;
        for(int j = 1;j <= tot && (ll)i * prime[j] <= n;j++)
        {
            vis[i * prime[j]] = true;
            if(i % prime[j] == 0)
            {
                mu[i * prime[j]] = 0;
                break;
            }
            mu[i * prime[j]] = -mu[i];
        }
    }
    for(int i = 1; i <= n; i ++) hold down [i] = hold down [i- 1 ] + mu [i]; 
} 

// 1≤i≤n, 1≤j≤m \ sigma [GCD (i, j) = 1] 
int solve ( int n, int m) 
{ 
    int no = 0 ;
    for ( int i = 1 , j; i <= min (n, m); i = j + 1 ) 
    { 
        j = min (n / (n / i) m / (m / i)); 
        nothing + = (hold down [j] -premu [i- 1 ]) * (n / i) * (m / e); 
    } 
    Return anything; 
} 

Int a, b, c, d, k; 

int    main ()
{
    getMu(maxn);
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d%d%d%d%d", &a, &b, &c, &d, &k);
        printf("%d\n", solve(b/k, d/k) - solve((a-1)/k, d/k) - solve(b/k, (c-1)/k) + solve((a-1)/k, (c-1)/k));
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/lfri/p/11310706.html