[BZOJ2226]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 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_…
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…
[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<…
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…
题目描述 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…
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…
Problem code: LCMSUM 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…
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*}\] 设\(…
题目链接: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…
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…
Description Given \(n\), calculate the sum \(LCM(1,n) + LCM(2,n) + \cdots + 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 ne…
题目: 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*(…
题意是求: $\sum_{i = 1}^{n}lcm(i, n)$ $= \sum_{i = 1}^{n}\frac{ni}{gcd(i, n)}$ $= n\sum_{i = 1}^{n}\frac{i}{gcd(i, n)}$ $= n\sum_{d|n}\sum_{i = 1}^{n}d*[gcd(i, n)==d]$ $= n\sum_{d|n}\sum_{i = 1}^{\frac{n}{d}}i*[gcd(i, \frac{n}{d})==1]$ $= n\sum_{d|n}\sum…
题目 [题目描述] 对于 $ A_1, A_2, \ldots, A_N $ ,求$\sum_{i = 1}^N \sum_{j = 1}^N \mathrm{lcm}(A_i, A_j)$ 的值. $ \mathrm{lcm}(a, b) $ 表示 $ a $ 和 $ b $ 的最小公倍数 [输入格式] 第 $ 1 $ 行, $ 1 $ 个整数 $ N $ . 第 $ 2 $ 行, $ N $ 个整数 $ A_1, A_2, \ldots, A_N $ . [输出格式] $ 1 $ 个整数,表…
题面 题目要我们求这个: \[\sum_{i=1}^n lcm(i,n)\] 开始化式子: \[\sum_{i=1}^{n} \frac{i*n}{gcd(i,n)}\] \[\sum_{d|n} \sum_{i=1}^{\frac{n}{d}} i*n[gcd(i,\frac{n}{d})=1]\] \[n*\sum_{d|n}\sum_{i=1}^{d}i[gcd(i,d)=1]\] 注意那个\(\sum_{i=1}^{d}i[gcd(i,d)=1]\)是求\([1,d]\)中所有与\(d\…
全场都 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 啊-- 然后到了今天-- 我自己用模板的方法(?)推…
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…
一个基于观察不依赖于反演的做法. 首先 \(\rm lcm\) 是不好算的,转化为计算 \(\rm gcd\) 的问题,求: \[\sum\limits_{i = 1} ^ n \frac{in}{\gcd(i, n)} \] 注意到 \(\gcd(n - i, n) = \gcd(i, n), (n - i) \times n + in = n ^ 2\),可以考虑将 \(\gcd(n - i, n), \gcd(i, n)\) 一起计算. 具体地,将原式乘 \(2\), 前后配对.需要注意的…
(总计:共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]开…
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…
2401: 陶陶的难题I Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 24[Submit][Status] Description 最近陶陶在研究数论,某天他偶然遇到一道题:对于给定的正整数���,求出 下面这样一个式子的值: 其中LCM(a���, b���)表示正整数���和���最小公倍数,即能同时被a���和b���整除的最小正 整数. 作为神犇的陶陶,当然轻松秒杀了这道题.不过他希望你写一个程序,用来 检验他算…
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem 10983 18765 Y 1036 [ZJOI2008]树的统计Count 5293 13132 Y 1588 [HNOI2002]营业额统计 5056 13607 1001 [BeiJing2006]狼抓兔子 4526 18386 Y 2002 [Hnoi2010]Bounce 弹飞绵羊 43…
gcd套路变换 GCD https://www.luogu.org/problem/P2568 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. $ 1<=N<=10^7$ 答案是n*n矩阵中每两个数之间gcd==1的数对个数 考虑把\(n\times n\)的矩阵分成两部分,即从对角线劈开,设每一部分的答案为ans,则最终答案为$ ans*2 - 对角线上的(即n以内的质数个数)$ 这个把矩阵分成两部分的方法很有用,记一下吧 \[ ans = \…
1040 最大公约数之和 给出一个n,求1-n这n个数,同n的最大公约数的和.比如:n = 6 1,2,3,4,5,6 同6的最大公约数分别为1,2,3,2,1,6,加在一起 = 15 输入 1个数N(N <= 10^9) 输出 公约数之和 输入样例 6 输出样例 15 题解 \[ \sum_{i=1}^n\gcd(i,n)=\sum_{d|n}d\varphi(n) \] 暴力搞就行了. 1188 最大公约数之和 V2 给出一个数N,输出小于等于N的所有数,两两之间的最大公约数之和. 相当于计…
不学莫反,不学狄卷,就不能叫学过数论 事实上大概也不是没学过吧,其实上赛季头一个月我就在学这东西,然鹅当时感觉没学透,连杜教筛复杂度都不会证明,所以现在只好重新来学一遍了(/wq 真·实现了水平的负增长((( 1. \(\mu\) 与 \(\varphi\) 真就从头开始呗 对于整数 \(n=p_1^{\alpha_1}\times p_2^{\alpha_2}\times\cdots\times p_k^{\alpha_k}\),定义莫比乌斯函数 \(\mu(n)\) 为: \[\mu(n)=…