BZOJ2226: [Spoj 5971] LCMSum】的更多相关文章

题解: 考虑枚举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…
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*}\] 设\(…
题目描述 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…
题目: 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*(…
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…
题目链接:LCMSum 这个题显然就是要我们推式子了……那么就来推一波: \begin{aligned}&\sum_{i=1}^n lcm(i,n) \\=&\sum_{i=1}^n\frac{ni}{\gcd(i,n)} \\=&n\sum_{d|n}\sum_{i=1}^{\frac{n}{d}}\frac{di[\gcd(i,\frac{n}{d})=1]}{d} \\=&n\sum_{d|n}\sum_{i=1}^{d}i[\gcd(i,d)=1]\end{alig…
全场都 AK 了就我爆 0 了 题意 \(t\) 组询问,每组询问给定 \(n\),求 \(\sum\limits_{k=1}^n [n,k]\).其中 \([a,b]\) 表示 \(a\) 和 \(b\) 的最小公倍数. \(t\le 3\times 10^5,\space n\le 10^6\) 题解 怎么全世界都做过这题啊 前一天晚上听林老师说今天 T1 是莫比乌斯反演,然后我就出了一身冷汗--我没做过几道莫反,推不出来式子会不会被 D 啊-- 然后到了今天-- 我自己用模板的方法(?)推…