bzoj 2301: [HAOI2011]Problem b (反演)
来源:互联网 发布:c语言需要掌握 编辑:程序博客网 时间:2024/05/16 13:52
题目描述
传送门
题目大意:
题解
然后式子变成了类似的四部分
利用
预处理前缀和,就可以用
代码
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#define ll long long #define N 50000using namespace std;int mu[N+3],prime[N+3],pd[N+3];int n,m,t,a,b,c,d,k,sum[N+3];void calc(){ mu[1]=1; sum[1]=mu[1]; for (int i=2;i<=N;i++) { if (!pd[i]) { prime[++prime[0]]=i; mu[i]=-1; } for (int j=1;j<=prime[0];j++) { if (i*prime[j]>N) break; pd[i*prime[j]]=1; if (i%prime[j]==0) { mu[i*prime[j]]=0; break; } else mu[i*prime[j]]=-mu[i]; } sum[i]=sum[i-1]+mu[i]; }}int solve(int a,int b){ if (a>b) swap(a,b); int j=0; int ans=0; for (int i=1;i<=a;i=j+1) { j=min(a/(a/i),b/(b/i)); ans=ans+(sum[j]-sum[i-1])*(a/i)*(b/i); } return ans;}int main(){ scanf("%d",&t); calc(); for (int T=1;T<=t;T++) { scanf("%d%d%d%d%d",&a,&c,&b,&d,&k); a--; b--; c/=k; d/=k; a/=k; b/=k; int ans=solve(c,d)-solve(a,d)-solve(b,c)+solve(a,b); printf("%d\n",ans); } return 0;}
0 0
- bzoj 2301: [HAOI2011]Problem b (反演)
- BZOJ 2301([HAOI2011]Problem b-mobius反演)
- [BZOJ 2301][HAOI2011] Problem b 莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 【莫比乌斯反演】
- BZOJ 2301: [HAOI2011]Problem b - 莫比乌斯反演
- [莫比乌斯反演] BZOJ 2301 [HAOI2011]Problem b
- BZOJ 2301: [HAOI2011]Problem b【莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b 莫比乌斯反演
- bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演 + 容斥原理 + 分块优化)
- BZOJ 2301: [HAOI2011]Problem b(莫比乌斯反演,分块,容斥)
- BZOJ 2301 [HAOI2011]Problem b (莫比乌斯反演)
- 莫比乌斯反演(bzoj 2301: [HAOI2011]Problem b)
- BZOJ 2301 [HAOI2011]Problem b (莫比乌斯反演)
- bzoj 2301 [HAOI2011]Problem b (莫比乌斯反演)
- BZOJ 2301: [HAOI2011]Problem b
- bzoj 2301: [HAOI2011]Problem b
- android源码下载与编译
- js运行报错:(intermediate value) is not a function
- 并行处理提高工作效率
- Leetcode 407. Trapping Rain Water II
- TP 框架 常识
- bzoj 2301: [HAOI2011]Problem b (反演)
- 天梯赛决赛题目
- 内部类
- 开源库编译
- Mina框架 open to many file 错误原因以及解决方案
- 关于科研
- MapReduce二次排序(secondary sort)实战
- Python3 requests包学习
- Easyui使用formatter格式化单元格为空解决办法