Description Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b 1, b 2, …, b N. which satisfies : 1. F…
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 num…
/** 题目:hdu4675 GCD of Sequence 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4675 题意:给定n个数的a数组,以及m,k: 构造满足1<=bi<=m,和a数组恰好k个位置ai!=bi的b数组. 输出b数组所有数的gcd分别为1~m的数组个数. 思路: f(n)表示gcd==n的数组个数. g(n)表示gcd是n的倍数的数组个数. f(n) = sigma[n|d]mu[d/n]*g(d); 如何求g(d)呢? 如果没…
Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● a i ∈ [0,n] ● a i ≠ a j( i ≠ j ) For sequence a and sequence b, the integrating degree t is defined as follows(“�” denotes exclus…
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N integers a 1, a 2, -, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b…
Description Edward has a set of n integers {a1, a2,...,an}. He randomly picks a nonempty subset {x1, x2,…,xm} (each nonempty subset has equal probability to be picked), and would like to know the expectation of [gcd(x1, x2,…,xm)]k. Note that gcd(x1, …
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 Hint 对于样例(2,2),(2,4),(3,3),(4,2) 1<=N<=10^7 这个题目可以用欧拉函数或者莫比乌斯反演. 第一种欧拉函数: 因为gcd(x, y) = p,所以gcd(x/p, y/p) = 1. 不妨设y较大,那么就是求所有比y/p小的数k,ph…
Description As we know, any positive integer C ( C >= 2 ) can be written as the multiply of some prime numbers:      C = p1×p2× p3× ... × pk  which p1, p2 ... pk are all prime numbers.For example, if C = 24, then:      24 = 2 × 2 × 2 × 3      here, p…
http://acm.hdu.edu.cn/showproblem.php?pid=5667 这题的关键是处理指数,因为最后结果是a^t这种的,主要是如何计算t. 发现t是一个递推式,t(n) = c*t(n-1)+t(n-2)+b.这样的话就可以使用矩阵快速幂进行计算了. 设列矩阵[t(n), t(n-1), 1],它可以由[t(n-1), t(n-2), 1]乘上一个3*3的矩阵得到这个矩阵为:{[c, 1, b], [1, 0, 0], [0, 0, 1]},这样指数部分就可以矩阵快速幂了…
Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example…