BZOJ2226 & SPOJ5971:LCMSum——题解】的更多相关文章

2226: [Spoj 5971] LCMSum Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 1949  Solved: 852[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…
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 next T lines contain an intege…
LCMSum bzoj-2226 Spoj-5971 题目大意:求$\sum\limits_{i=1}^nlcm(i,n)$ 注释:$1\le n\le 10^6$,$1\le cases \le 3\cdot 10^5$. 想法:$\sum\limits_{i=1}^nlcm(i,n)$ $=\sum\limits_{i=1}^n\frac{in}{gcd(i,n)}$ $=n\cdot \sum\limits_{i=1}^n \frac{i}{gcd(i,n)}$ $=n\cdot \sum…
http://www.lydsy.com/JudgeOnline/problem.php?id=2226 题目大意:给定一个n,求lcm(1,n)+lcm(2,n)+……+lcm(n,n). —————————————————————————————— 如果是刚做完[SDOI2012]Longge的问题的话这道题应该能轻松一些. 显然答案可以转化为∑n*i/gcd(n,i). 设k=gcd(n,i),则可以转化为∑n*i/k(k|n且gcd(n,i)=k),然后变成n*(∑i/k)(k|n且gc…
(总计:共90题) 3.10~3.16:17题 3.17~3.23:6题 3.24~3.30:17题 3.31~4.6:21题 4.7~4.12:29题 ZJOI&&FJOI(6题) TJOI2016(6题) 六省联考2017(6题) SDOI2016(3题) HNOI2013(6题) CQOI2017(3题) 九省联考2018(3题) 3.10 [BZOJ4552][TJOI2016&&HEOI2016]排序(二分答案+线段树) [BZOJ4012][HNOI2015]开…
[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…
题解: 考虑枚举gcd,然后问题转化为求<=n且与n互质的数的和. 这是有公式的f[i]=phi[i]*i/2 然后卡一卡时就可以过了. 代码: #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<…
题目描述 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…
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 next T lines contain an intege…
转化一下,$\sum\limits_{i=1}^n[i,n]=n\sum\limits_{i=1}^n\dfrac i{(i,n)}$ 枚举$d=(i,n)$,上式变为$n\sum\limits_{d=1}^n\sum\limits_{i=1}^n[(i,n)=d]\dfrac id=n\sum\limits_{d|n}\sum\limits_{i=1}^{\frac nd}\left[\left(i,\dfrac nd\right)=1\right]i$ 设$f(n)=\sum\limits_…