bzoj 3739: DZY loves math VIII (数学)
来源:互联网 发布:python curl post 编辑:程序博客网 时间:2024/06/03 16:50
题目描述
传送门
题目大意:
题解
另
这个东西可以动态的维护,每次加入一个数,如果这个数有贡献,那么他一定是几个质数一次方的乘积。那么我们可以dfs得到他所有的约数,然后用
代码
#include<cstdio>#include<algorithm>#define N 10000000using namespace std;int T,pd[N+10],prime[N+10],mu[N+10],ans[1003],n,a[N],p[N+10];int cnt,st[103],f[N+10],sum[N+10];void init(){ mu[1]=1; for (int i=2;i<=n;i++) { if (!pd[i]) { prime[++prime[0]]=i; p[i]=i; mu[i]=-1; } for (int j=1;j<=prime[0];j++){ if (i*prime[j]>n) break; pd[i*prime[j]]=1; p[i*prime[j]]=prime[j]; if (i%prime[j]==0) break; mu[i*prime[j]]=-mu[i]; } }}int dfs(int num,int x,int v){ if (num==cnt+1) { f[x]+=v; return mu[x]*f[x]; } return dfs(num+1,x*st[num],v)+dfs(num+1,x,v);}int main(){ freopen("a.in","r",stdin); scanf("%d",&T); for (int i=1;i<=T;i++) scanf("%d",&a[i]),n=max(n,a[i]); init(); for (int i=1;i<=n;i++) { sum[i]=sum[i-1]; if (!mu[i]) continue; cnt=0; int x=i; for (;x>1;x/=p[x]) st[++cnt]=p[x]; sum[i]+=mu[i]*dfs(1,1,mu[i]); } for (int i=1;i<=T;i++) printf("%d\n",sum[a[i]]);}
阅读全文
0 0
- bzoj 3739: DZY loves math VIII (数学)
- bzoj 3739 DZY loves math VIII
- 【bzoj 3739】DZY loves math VIII - 乱搞数学题
- BZOJ3739: DZY loves math VIII
- bzoj 3309: DZY Loves Math (反演)
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- bzoj3739 DZY loves math VIII 莫比乌斯函数
- 【线性筛】【bzoj 3309】: DZY Loves Math
- BZOJ 3560 DZY Loves Math V 数论
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- BZOJ 3512: DZY Loves Math IV
- [杜教筛] BZOJ 3512 DZY Loves Math IV
- 【BZOJ 3560】【数论】DZY Loves Math V
- 关于ES、PES、PS以及TS码流
- Initializing Spring root WebApplicationContext
- 堆排序
- python第25篇之--类的继承
- 【机器学习算法模型】分类决策树——ID3
- bzoj 3739: DZY loves math VIII (数学)
- 及时尽孝,别枉读了大学
- 【Python】BeautifulSoup简介02
- 键盘事件监听演示代码
- 有关信息抽取的文章列表(1)
- 关于分布式的一些理论和概念
- Happy Chicken Run
- Python基础——高级特性
- python第26篇之--文件IO