CF1016G Appropriate Team [Pollard-rho,FMT]

Title description: Given \ (n, X, Y \) and \ (n \) positive integers \ (a_i \) , how many \ ((i, j) \) to make \ (\ exist v, \ gcd (a_i, v) = X, \ text {lcm} (a_j, v) = Y \) .

Data range: \ (n \ le 2 \ times 10 ^ 5, a_i, X, Y \ le 10 ^ {18} \)

First of all, \ (X \ not | Y \) , this must be \ (0 \) .

Then we use Pollard-rho to decompose \ (Y \) into prime factors, and then use \ (Y \) 's prime factors to decompose other numbers.

If \ (X | a_i \) , then consider the possible number of \ (v \) for each prime factor of \ (Y \) .

Then, if the number of \ (X \) on a prime factor is the same as \ (a_i \) , then the number of \ (v \) can be no less than the number of times of \ (X \) . Otherwise , the number of \ (v \) must be the same as \ (X \) .

Since the number of prime factors of \ (Y \) does not exceed \ (18 \) , we press the set of prime factors that must have the same number of \ (v \) as \ (X \) and record it as \ (SX_i \) .

If \ (a_i | Y \) , then consider the possible number of \ (v \) for each prime factor of \ (Y \) .

Then if the number of \ (Y \) on a prime factor is the same as \ (a_i \) , then the number of \ (v \) can be arbitrarily not greater than the number of times of \ (Y \) . Otherwise , the number of \ (v \) must be the same as \ (Y \) . Also press the same must be recorded as \ (SY_i \) .

Let \ (X \) and \ (Y \) have different prime factors set to \ (SS \) , then \ ((i, j) \) meets the requirements if and only if \ (SX_i \ cap SY_j \ cap SS = 0 \) .

This can be calculated using Fans MeeTing FMT, time complexity \ (O (Y ^ \ frac {1} {4} + (n + 2 ^ {\ omega (Y)}) \ omega (Y)) \) .

code

Guess you like

Origin www.cnblogs.com/AThousandMoons/p/12675691.html