诶,莫比乌斯反演,OI界还是有很多高大上的词汇的嘛(666…我好自恋)
还是回到正题,首先来讲一讲莫比乌斯反演的预备知识吧。
首先是这个符号[ ],
这是一个逻辑格符号,当方括号中的式子成立的时候,值为1,反之,值为0。
然后大家看看欧拉函数和积性函数的定义及应用,大家可以自行上网查询一下,因为这都是烂大街的东西(无形装逼。。)。
然后就是容斥定理,总的来说还是很好理解的,网上有很多关于它的论文。
简单解释一下就是假如A是一个有限集合,元素个数|A|为n,令A1是A中具有性质P1的元素组成的集合。那么假如要求A中不具有性质P1,P2的元素个数为N,那么就可以很容易得出N=|A|-|A1|-|A2|+|A1并A2|(求原谅,弱鸡不会打符号)
为什么要重新加上|A1并A2|呢。。
大家想一想啊,|A1|,|A2|之中难道元素都只有性质P1,P2吗,肯定不是辣,所以加上|A1并A2|,就是为了眷顾重复减去的的元素,所以再把它们加上。
终于到了正式的啦。
那么首先大家知道莫比乌斯反演有两种形式:
形式1:
如果 f(n)=∑ d|n g(d)
那么 g(n)=∑ d|n μ(d)f(n/d )
形式二:
如果 f(n)=∑ n|d g(d)
那么 g(n)=∑ n|d μ(d/n)f(d)
那么以上就是莫比乌斯反演的基本形式啦。
有人说,哇哇哇哇,但不懂。。。
借用NEXplain大神的一道题
1、GCD
Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Given 5 integers: a, b, c, d, k, you’re to find x in a…b, y in c…d that GCD(x, y) = k. GCD(x, y) means the greatest common divisor of x and y. Since the number of choices may be very large, you’re only required to output the total number of different number pairs.
Please notice that, (x=5, y=7) and (x=7, y=5) are considered to be the same.
You can assume that a = c = 1 in all test cases.
Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 3,000 cases.
Each case contains five integers: a, b, c, d, k, 0 < a <= b <= 100,000, 0 < c <= d <= 100,000, 0 <= k <= 100,000, as described above.
Output
For each test case, print the number of choices. Use the format in the example.
Sample Input
2
1 3 1 5 1
1 11014 1 14409 9
Sample Output
Case 1: 9
Case 2: 736427
Hint
For the first sample input, all the 9 pairs of numbers are (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 5), (3, 4), (3, 5).
1
问题简述之就是1<=x<=n,1<=y<=m中gcd(x,y)==k的组数
求得就是∑(1≤x≤n)∑(1≤y≤m)〖gcd(x,y)==k〗的组数。
那么让f(k)表示1<=x<=n,1<=y<=m中gcd(x,y)==k的组数。
再让F(k)表示1<=x<=n,1<=y<=m中gcd(x,y)是k的倍数的组数。
因为这个问题满足莫比乌斯反演的第二种形式
那么即F(k)=∑_(k|d) f(d)
可以求得F(k)=∑(k|d) mu(d/k)f(d)
那么F(k)我们知道是[n/k]*[m/k]
所以此题便可求。
但凡事都涉及到一个效率问题。
所以要进行转化。
1<=x<=n ,1<=y<=m中 gcd(x,y)==k 的对数相当于 1<=x<=n/k 1<=y<=m/k 中gcd(x,y) == 1的对数。
明白这句话后就继续,
f(1)=∑(k|d)mu(d)F(d)=∑d mu(d)[n/k][m/k]
哈哈,庆幸吧,终于把这一切的一切转化成连续值求和了。
这样问题得以完美解决。
写着写着就发现不对,我居然不会打符号,唉,谁叫我是弱鸡呢,我一定要学会。。【奋斗!!】对不起大家了。