Http://www.lydsy.com/JudgeOnline/problem.php?id=1101
Infinite Worship number theory and chunking Orz
First, some properties of Möbius function can be seen in "Elementary number Theory" or "concrete mathematics" or Jia Zhipeng "linear sieve method and product function"
Let me write some notes.
First, the definition of Möbius function and some properties (exemption from proof):
$$
\MU (n) =
\begin{cases}
1 & n=1\\
( -1) ^k & n=p_1p_2 \cdots P_k, the quality Factor index is 1 and different \ \
0 & other conditions \ \
\end{cases}
$$
By defining a linear sieve, it is easy to preprocess it, and I will not elaborate.
Then the nature:
$$ \sum_{d|n} \mu (d) = [n=1]$$
I haven't learned Orz for the time being inversion.
and then ask.
$$\sum_{1<=x<=a} \sum_{1<=y<=b} [(x, Y) =d]$$
So we simplify, first of all according to $ (A, B) =x \rightarrow (DA, DB) =dx$, then the subject is the request
$$\sum_{1<=x<=a '} \sum_{1<=y<=b '} [(x, Y) =1], where a ' =a/d, B ' =b/d$$
Continue simplifying, according to $\sum_{d|n} \mu (d) = [n=1]$
$$\sum_{1<=x<=a '} \sum_{1<=y<=b '} \sum_{d| ( x, y)} \mu (d) $$
In advance and in accordance with the $a|- (x, y) \rightarrow a|x, a|y$, with
$$\sum_{1<=d<=min\{a ', B ' \}} \mu (d) \sum_{1<=x<=a ' and d|x} \sum_{1<=y<=b ' and D|y} 1$$
You can see that the original is:
$$\sum_{1<=d<=min\{a ', B ' \}} \mu (d) \lfloor \frac{a '}{d} \rfloor \times \lfloor \frac{b '}{d} \rfloor$$
And we found that $\lfloor \frac{a '}{d} \rfloor$ only $2\sqrt{a '}$ species (that is, there are so many vendors), B ' so we can split blocks!
Calculates all numbers of the same quotient each time. And because it is a type, we can maintain a prefix and become a multiplication!
and calculate the current quotient of the next business is very clever!
pos=n/(N/now), is the current divisor, POS is the current quotient of the last divisor, pos+1 is the next divisor (making different from the current quotient)!
Because N/now draws the current quotient, and then besides N, can get all the quotient for N/now number of the last number,,,,,, very simple primary problem Qaqorz
So the problem is solved.
#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map>using namespace std; typedef long Long LL; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a); i<= (n); ++i) #define For2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n); i.) #define FOR4 (i,a,n) for (int i= ( a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define PRINT (a) printf ("%d", a) # Define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (! x)? puts ("Error"): 0) Inline const int Getint () {int r=0, k=1; char C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; } #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) const int N=50015;int mu[n], p[n], np[n], CNT, sum[n];void init () {mu[1]=1;for (int i=2; i<n; ++i) {if (!np[i]) p[++cnt]=i, mu[i]=-1;for (int j=1; j<=cnt && i*p[j]<n; ++j) { int T=i*p[j];np[t]=1;if (i%p[j]==0) {mu[t]=0; break;} Mu[t]=-mu[i];}} for (int i=1; i<n; ++i) sum[i]=sum[i-1]+mu[i];} int main () {int A, B, D, N=getint (), Init (), while (n--) {read (a); Read (b); read (d); A/=d, B/=d;int l=min (A, B), Pos;ll ans=0; for (int i=1; i<=l; i=pos+1) {pos=min (A/(a/i), b/(b/i)), ans+= (LL) (Sum[pos]-sum[i-1]) * (a/i) * (b/i);} printf ("%lld\n", ans);} return 0;}
Description
FGD is cracking a cipher, and he needs to answer a number of similar questions: for a given integer, a, B, and D, how many positive integers are to X, Y, X<=a,y<=b, and gcd (x, y) =d. As a classmate of FGD, FGD hopes to get your help.
Input
The first line contains a positive integer n, which indicates that there are altogether n groups of queries. (1<=n<= 50000) next n rows, each line represents a query, three positive integers per line, respectively, A,b,d. (1<=d<=a,b<=50000)
Output
For each set of queries, output to the output file zap.out a positive integer that represents the integer logarithm that satisfies the condition.
Sample Input2
4 5 2
6 4 3Sample Output3
2HINT
For the first set of queries, an integer pair that satisfies the condition has (2,2), (2,4), (4,2). For the second set of queries, an integer pair that satisfies the condition has (6,3), (3,3).
Source
"Bzoj" 1101: [Poi2007]zap (Möbius + chunked)