题目: http://www.lydsy.com/JudgeOnline/problem.php?id=2226 题解: 题目要求的是Σn*i/gcd(i,n) i∈[1,n] 把n提出来变成Σi/gcd(i,n) i∈[1,n] 最后乘个n 设gcd(i,n)==d 我们枚举约数可以得到 ∑(∑i/d*(gcd(i,n)==d)) (外面的Σ枚举d) 把i/d这个式子除以d可以得到 Σ( Σj*(gcd(j,n/d)==1) ) (外面Σ枚举d,j与n互质) 由于n/d与d等价 Σ( Σj*(…
2226: [Spoj 5971] LCMSum Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 578  Solved: 259[Submit][Status] Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i a…
BZOJ 2226 [Spoj 5971] LCMSum 这道题和上一道题十分类似. \[\begin{align*} \sum_{i = 1}^{n}\operatorname{LCM}(i, n) &= \sum_{i = 1}^{n}\frac{i \times n}{\operatorname{gcd}(i, n)}\\ &= n \times \sum_{i = 1}^{n}\frac{i}{\operatorname{gcd}(i, n)} \end{align*}\] 设\(…
Code: #pragma GCC optimize(2) #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #define maxn 1000006 #define M 1000004 #define ll long long using namespace std; char *p1,*p2,buf[100000]; #define nc() (p1==p2&…
题解:枚举gcd,算每个gcd对答案的贡献,贡献用到欧拉函数的一个结论 最后用nlogn预处理一下,O(1)出答案 把long long 打成int 竟然没看出来QWQ #include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; const int maxn=1000009; const int u=1000000; typedef lo…
题解: 考虑枚举gcd,然后问题转化为求<=n且与n互质的数的和. 这是有公式的f[i]=phi[i]*i/2 然后卡一卡时就可以过了. 代码: #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<…
[BZOJ2226][Spoj 5971] LCMSum Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i and n. Input The first line contains T the number of test cases. Each of the n…
题目描述 Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i and n. 输入 The first line contains T the number of test cases. Each of the next T lines contain an integer n. 输出 Ou…
2226: [Spoj 5971] LCMSum Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1123  Solved: 492[Submit][Status][Discuss] Description Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the in…
目录 题意 思路 AC_Code1 AC_Code2 AC_Code3 参考 @(bzoj 2780: [Spoj]8093 Sevenk Love Oimaster) 题意 链接:here 有\(n\)个大串\(s\)和\(m\)个询问,每次给出一个字符串\(t\)询问在多少个大串中出现过. \(1\le n\le 10000,1\le m\le 60000,\sum|s|\le 100000,\sum |t|\le 360000\) 思路 初步分析 对\(n\)个串建广义后缀自动机(每个串插…