http://acm.hdu.edu.cn/showproblem.php?pid=5212

题意:忽略。。

题解:把题目转化为求每个gcd的贡献。(http://www.cnblogs.com/z1141000271/p/7419717.html 和这题类似 反向容斥)这里先用容斥写了,mobious的之后再说吧23333。

然后比较想说的是这个调和级数的复杂度 nlog(n)

ac代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#define mt(a) memset(a,0,sizeof(a))
using namespace std;
const int mod=;
typedef long long ll;
ll a[];
ll num[];
ll cnt[];
ll get(ll n)
{
int f=;
f=n*n;
f%=mod;
return f;
}
int main()
{
ll n;
while(~scanf("%lld",&n))
{
ll mx=-;
mt(a);
mt(cnt);
mt(num);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
num[a[i]]++;
mx=max(mx,a[i]);
}
ll ans=;
for(ll i=mx;i>=;i--)
{
int ret=num[i];
for(int j=i*;j<=mx;j+=i)
{
cnt[i]=(cnt[i]-cnt[j]+mod)%mod;
ret+=num[j];
}
// cout<<ret<<endl;
cnt[i]+=get(ret);//想清楚。
cnt[i]+=mod;
cnt[i]%=mod;
ll p=i*(i-)%mod;
ans=(ans+(cnt[i]*p))%mod;
}
cout<<ans<<endl;
}
return ;
}

hdu 5212 反向容斥或者莫比的更多相关文章

  1. hdu 5514 Frogs(容斥)

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  2. HDU 5213 分块 容斥

    给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...

  3. HDU 2588 思维 容斥

    求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...

  4. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  5. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  6. hdu 5768 Lucky7 容斥

    Lucky7 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...

  7. HDU5213(容斥定理+莫队算法)

    传送门 题意 给出n个数和幸运数k,m次询问,每次询问[l1,r1]和[l2,r2]有多少对数满足x+y=k,x∈[l1,r1],y∈[l2,r2] 分析 看到m只有3e4,可以考虑\(m\sqrt{ ...

  8. ACM-ICPC 2015 沈阳赛区现场赛 F. Frogs && HDU 5514(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意:有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过xi个石子.问所 ...

  9. hdu 1695 GCD 容斥+欧拉函数

    题目链接 求 $ x\in[1, a] , y \in [1, b] $ 内 \(gcd(x, y) = k\)的(x, y)的对数. 问题等价于$ x\in[1, a/k] , y \in [1, ...

随机推荐

  1. spring boot + vue 前后分离实现登录功能(一)

    使用webpack 打包初始化项目 vue init webpack book-vue 进入工程目录 cd hello-vue 安装 vue-router npm install vue-router ...

  2. excel_vlookup函数_python代码实现

    python入门经典视频系列教程(免费,2K超清,送书) https://study.163.com/course/courseMain.htm?courseId=1006183019&sha ...

  3. Mac中好用的快捷键

    1.safari safariy页面刷新:Command+R,类似于Win系统里面的F5

  4. websphere 英文版部署(更新)项目【我】

    websphere 部署(更新)项目 首先在控制台页面依次点左侧,打开应用配置页面: 然后在右侧勾选我们要重新部署的项目,首先点上面的 停止 按钮,等项目停止后,再勾选项目,点上面的  更新 按钮(如 ...

  5. 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_04-用户认证-认证服务查询数据库-查询用户接口-接口开发

    定义dao 权限放在授权的课程里面做,现在先不管.我们还需要查企业信息,就是用户所属的公司 公司表 对应关系在xc_company 这是一个关系 表 这个表里有唯一索引 user_id 所以根据use ...

  6. CentOS7下配置Tomcat以APR模式+Tomcat Native运行

    在慢速网络上Tomcat线程数开到300以上的水平,不配APR,基本上300个线程狠快就会用满,以后的请求就只好等待.但是配上APR之后,Tomcat将以JNI的形式调用Apache HTTP服务器的 ...

  7. 学习 TTreeView [16] - 给 TTreeView 添加复选框 (回复 "丁永其" 的问题)

    问题来源: http://www.cnblogs.com/del/archive/2008/05/15/1114450.html#1199402 本例效果图: unit Unit1; interfac ...

  8. [LeetCode] 167. Fraction to Recurring Decimal 分数转循环小数

    Given two integers representing the numerator and denominator of a fraction, return the fraction in ...

  9. Android studio之广播监听接收短信

    一. 在清单文件中(AndroidManifest.xml)添加短信权限 这里我用的android studio版本是3.3的 <uses-permission android:name=&qu ...

  10. Egret入门学习日记 --- 问题汇总

    问题1: 图片无法拖入到 EXML 文件的问题 在日记 第六篇 有记载:https://www.cnblogs.com/dmc-nero/p/11188975.html 位于 3.6节 内容. 问题2 ...