正题

题目链接:
https://www.lydsy.com/JudgeOnline/problem.php?id=2226
https://www.luogu.org/problem/SP5971


题目大意

求∑i=1nlcm(n,i)\sum_{i=1}^n lcm(n,i)i=1∑n​lcm(n,i)


解题思路

∑i=1nlcm(n,i)\sum_{i=1}^n lcm(n,i)i=1∑n​lcm(n,i)
∑i=1nnigcd(n,i)\sum_{i=1}^n \frac{ni}{gcd(n,i)}i=1∑n​gcd(n,i)ni​
n∑d∣n∑i=1n[(n,i)==d]in\sum_{d\mid n}\sum_{i=1}^n[(n,i)==d]ind∣n∑​i=1∑n​[(n,i)==d]i
n∑d∣n∑i=1n[(n/d,i/d)==1]in\sum_{d\mid n}\sum_{i=1}^n[(n/d,i/d)==1]ind∣n∑​i=1∑n​[(n/d,i/d)==1]i
n∑d∣nd∗φ(d)2n\sum_{d|n}\frac{d*\varphi(d)}{2}nd∣n∑​2d∗φ(d)​

然后预处理O(nlog⁡n)O(n\log n)O(nlogn)然后O(1)O(1)O(1)回答即可

时间复杂度O(nlog⁡n+T)O(n\log n+T)O(nlogn+T)


codecodecode

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=1e6;
ll T,phi[N+10],ans[N+10],n;
int main()
{for (ll i=2;i<=N;i++) phi[i]=i;for (ll i=2;i<=N;i++){bool flag=(phi[i]==i);for (ll j=i;j<=N;j+=i){if(flag)phi[j]=phi[j]/i*(i-1);ans[j]+=phi[i]*i/2;}}scanf("%lld",&T);while(T--){scanf("%lld",&n);printf("%lld\n",n*(ans[n]+1));}
}

bzoj2226-[Spoj5971]LCMSum【欧拉函数,GCD】相关推荐

  1. 【bzoj2226】[Spoj 5971] LCMSum 欧拉函数

    题目描述 Given n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Leas ...

  2. 中gcd函数_欧拉函数φ(n)的计算及欧拉定理

    1 欧拉函数定义 在数论中,对正整数n,欧拉函数φ(n)是小于或等于n的正整数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为φ函数(由高斯所命名)或是欧拉总计函数(totient fun ...

  3. hdu (欧拉函数+容斥原理) GCD

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...

  4. hdu 4983 Goffi and GCD(欧拉函数)

    Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...

  5. jzoj3509-倒霉的小C【gcd,欧拉函数】

    正题 大意 画n条线,每次坐标变换为(x+n,y+(−1)(i+1)∗i)(i=1∼n)(x+n,y+(-1)^{(i+1)}*i) \ \ \ (i=1\sim n)(x+n,y+(−1)(i+1) ...

  6. [BZOJ2818][P2568]Gcd[欧拉函数]

    \(gcd(x,y)=p | p∈P\) \(gcd(x_1\times p,y_1\times p) = p\) \(gcd(x_1,y_1)=1\) 每个素数的贡献是对于\([1,\lfloor\ ...

  7. GCD - Extreme(欧拉函数变形)

    题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的 ...

  8. UVA11424 GCD - Extreme (I)【欧拉函数打表】

    Given the value of N, you will have to find the value of G. The definition of G is given below: G=∑i ...

  9. UVA11426 GCD - Extreme (II)【欧拉函数】

    Given the value of N, you will have to find the value of G. The definition of G is given below: G=∑i ...

最新文章

  1. redux+react-router报错
  2. mac云显卡服务器_重磅!NVIDIA GeForce NOW登陆Mac:云显卡玩吃鸡逆天
  3. printf,fprintf(stdout,stderr),sprintf等的使用方法及区别
  4. Ubuntu开机黑屏解决办法
  5. JeeWx 微信开发公开课(Jeewx-API 专题),今晚8点不见不散
  6. 深入理解JVM--类的执行机制
  7. Hibernate之session的管理方式
  8. python 求解给定字符串中的最长DNA序列长度
  9. Axure插件axure-chrome-extension安装(非常方便)
  10. 【Appium】手机按键(比如返回键、Home键等)的数字代号总结
  11. POI word 模板 字段替换
  12. 无人驾驶:高精地图与定位
  13. PD虚拟机最佳化内存设置,让Windows更加好用
  14. 第十二章:email-mailbox:管理email归档-imaplib:IMAP4客户库-连接服务器(认证失败)
  15. PDPS15.0机器人汽车件焊接 喷涂 人机仿真视频教程
  16. 课时8-2:adams建约束副----凸轮约束(平面推杆、尖底推杆)高副(点面、面面接触)
  17. 如何隐藏html路径,怎么显示隐藏文件夹
  18. CSP201803-4棋局评估
  19. 正则化最小二乘法——神经网络与机器学习笔记2
  20. 修复Edge浏览器无法登录微软账户问题

热门文章

  1. 金蝶显示服务器异常,金蝶提示云服务器异常
  2. 钣金缺口lisp_UG用钣金模块的放样创建天圆地方,还能学钣金展开,必看
  3. post多个参数_关于HTTP GET和POST的区别
  4. 算法设计与分析——动态规划——数字三角形问题
  5. 读取oracle bfile字段,ORACLE中BFILE字段的使用研究_oracle
  6. 计算机专业可以报考放射医学吗吗,文科生可以报考医学影像技术专业吗
  7. 布斯乘法以及带符号数的运算
  8. Jin Ge Jin Qu hao UVA - 12563 (劲歌金曲)01背包,求装入的东西最多(相同多时价值大)
  9. 数据结构 旅游规划(Dijkstra+Dfs)
  10. Java开发Web Service的简介