agc38C LCMs
https://atcoder.jp/contests/agc038/tasks/agc038_c
题意:给\(a_i\),求\(\sum_{i=1}^n\sum_{j=i+1}^nlcm(a_i,a_j)\)
题解:设\(\sum_{d|i}c_d=\frac{1}{i}\),\(O(nlogn)\)求出\(c_i\)
\(\sum_{i=1}^n\sum_{j=i+1}^nlcm(a_i,a_j)\)
\(=\sum_{i=1}^n\sum_{j=i+1}^n\frac{a_i\cdot a_j}{gcd(a_i,a_j)}\)
\(=\sum_{i=1}^n\sum_{j=i+1}^na_i\cdot a_j \cdot \sum_{d|a_i,d|a_j}c_d\)
\(=\sum_{i=1}^{ma}c_i\sum_{d|a_i,d|a_j,i<j}a_i\cdot a_j\)
总复杂度\(O(nlogn)\)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1000000+10,maxn=2000000+10,inf=0x3f3f3f3f;
ll a[N],b[N],c[N];
int main()
{
int n,ma=0;scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]),b[a[i]]++,ma=max(ma,(int)a[i]);
ll ans=0;
for(int i=1;i<=ma;i++)c[i]=qp(i,mod-2);
for(int i=1;i<=ma;i++)
for(int j=2*i;j<=ma;j+=i)
sub(c[j],c[i]);
for(int i=1;i<=ma;i++)
{
ll te=0,p=0;
for(int j=i;j<=ma;j+=i)
add(te,b[j]*j%mod),add(p,b[j]*j%mod*j%mod);
te=((te*te-p)%mod+mod)%mod;
te=te*qp(2,mod-2)%mod;
add(ans,te*c[i]%mod);
}
printf("%lld\n",ans);
return 0;
}
/********************
********************/
agc38C LCMs的更多相关文章
- LCMS
LCMS(LearningContent Management System) 即学习内容管理系统
- CF1166E The LCMs Must be Large
CF1166E The LCMs Must be Large 构造趣题 正着推其实很不好推 不妨大力猜结论 如果两两集合都有交,那么一定可以 证明: 1.显然如果两个集合没有交,一定不可以 2.否则给 ...
- Mol Cell Proteomics. | Prediction of LC-MS/MS properties of peptides from sequence by deep learning (通过深度学习技术根据肽段序列预测其LC-MS/MS谱特征) (解读人:梅占龙)
通过深度学习技术根据肽段序列预测其LC-MS/MS谱特征 解读人:梅占龙 质谱平台 文献名:Prediction of LC-MS/MS properties of peptides from se ...
- Fast and accurate bacterial species identification in urine specimens using LC-MS/MS mass spectrometry and machine learning (解读人:闫克强)
文献名:Fast and accurate bacterial species identification in urine specimens using LC-MS/MS mass spectr ...
- AT5200 [AGC038C] LCMs 莫比乌斯反演
LINK:LCMs 随便找了道题练习了一下莫比乌斯反演 式子有两个地方化简错误 导致查了1h的错. 讲一下大致思路 容易发现直接做事\(n^2logn\)的. 观察得到数字集合大小为1e6. 可以设\ ...
- 【讲座】朱正江——基于LC-MS的非靶向代谢组学
本次课程主题为<基于LC-MS的非靶向代谢组学>,主要分为代谢组学简介.代谢组学技术简介.非靶向代谢组学方法和数据采集.非靶向代谢组学数据分析和代谢物结构鉴定几个方面. 一.代谢组简介 基 ...
- CodeForces 1166E The LCMs Must be Large
题目链接:http://codeforces.com/problemset/problem/1166/E 说明 LCM(一个集合) 为这个集合中所有元素的最小公倍数. 如果$A \subseteq B ...
- Codeforces Round #561 (Div. 2) E. The LCMs Must be Large(数学)
传送门 题意: 有 n 个商店,第 i 个商店出售正整数 ai: Dora 买了 m 天的东西,第 i 天去了 si 个不同的个商店购买了 si 个数: Dora 的对手 Swiper 在第 i 天去 ...
- 数位DP入门
HDU 2089 不要62 DESC: 问l, r范围内的没有4和相邻62的数有多少个. #include <stdio.h> #include <string.h> #inc ...
随机推荐
- mongo数组修改器—$push、$ne、$addtoset、$pop、$pull
这几个方法也很有意思 $push 像已有的数组末尾加入一个元素,要是元素不存在,就会创建一个新的元素,如果元素存在了,就会再添加一个一模一样的元素,会造成元素的重复,所以在使用的时候,要确保该元素不存 ...
- 组合,模板,bolck块
如果前面和后面的变量名相同,则后面的变量名会覆盖前面的变量名 模板可以多次使用,只需要将is指定template的name,就可以重复使用该模板,只需要将不同的item值赋值给data就可以实现. 可 ...
- pandas 索引、选取和过滤
Series索引的工作方式类似于NumPy数组的索引,不过Series的索引值不只是整数,如: import numpy as np import pandas as pd from pandas i ...
- 解决Google Chrome浏览器字体模糊的问题
之前使用Google的Chrome浏览器一直觉得有时候,其显示的字体比较模糊,不管是Windows XP还是Windows 7都会出现要么显示的网页字体模糊,要么是Chrome浏览器本身显示的菜单模糊 ...
- RedHat版本Linux安装chrome-stable配合chromeDriver进行自动化测试环境准备
一.Linux机器安装google-chrome-stable 1.设置google-chrome软件源 sudo vim /etc/yum.repos.d/google-chrome.repo [g ...
- github合并分支到master
(1)切换到master分支 git checkout master (2) 将backup分支的代合并到master git merge backup (3) 查看状态 git status (4) ...
- 27 和为S的两个数字
0 引言 题目描述:输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 1 抽象问题具体化 举例: 序列为{1,2,3,4 ...
- Spring-Security (学习记录二)--修改为自己的登录页面
目录 1.修改spring-security.xml配置文件 2.增加login.jsp页面 3.重启项目即可看到效果 1.修改spring-security.xml配置文件 <!-- auto ...
- nutch集成solr和中文分词
nutch集成solr和中文分词 一.构建nutch环境 1. 设置代理 由于nutch使用ant构建,ant调用ivy,会从maven仓库中下载依赖包,因此若公司需要代理才能上网,需要设置代理,如果 ...
- JVM内核-原理、诊断与优化学习笔记(九):锁
文章目录 线程安全 多线程网站统计访问人数 多线程访问ArrayList 对象头Mark Mark Word,对象头的标记,32位 描述对象的hash.锁信息,垃圾回收标记,年龄 偏向锁 轻量级锁 B ...