转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove 题意:求sigma (gcd (i , j)) 1 <= i < j <= n 和POJ 2480类似,如果枚举j,求的话,还是会TLE的... 考虑sigma(gcd (i , n)) = sigma (d * phi[n / d]) d | n. 做法同样是先预处理出phi,然后枚举gcd = d. O(n)预处理,O(1)查询 #i…
tips : 积性函数 F (n) = Π F (piai ) 若F (n), G (n)是积性函数则 F (n) * G (n) Σd | n F (n) 是积性函数 n = Σd | n φ (d) 1 = Σd | n μ (d) Σgcd (i, n) = 1 i = n * φ (n) / 2 Problem1 F (n) = Σ1<= i <= n gcd(i, n), n <= 1000000 Sol 枚举结果 F (n) = Σd | n d * Σgcd (i, n…
题目 Source http://www.spoj.com/problems/DQUERY/en/ Description Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct elem…
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations: modify the i-th element in the sequence or for giv…
http://www.spoj.com/problems/SUBLEX/ 好难啊. 建出后缀自动机,然后在后缀自动机的每个状态上记录通过这个状态能走到的不同子串的数量.该状态能走到的所有状态的f值的和+1就是当前状态的f值. 最后对于询问的k,从root开始走顺便加加减减就可以了. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int in() { int k =…