bzoj2301
来源:互联网 发布:塔吊桩基础计算软件 编辑:程序博客网 时间:2024/06/03 19:57
bzoj2301
莫比乌斯反演
分块处理
参考了PoPoQQQ神的ppt
不懂为什么读入用cin就RE。QAQ
#include <bits/stdc++.h>using namespace std;const int N=50000+10;typedef long long LL;int prime[N],tot;int mu[N];int sum[N];void Mu(){ mu[1]=1; for (int i=2;i<N;i++){ if (!prime[i]){ prime[++tot] = i; mu[i]=-1; } for (int j=1;prime[j]*i<N;j++){ prime[ prime[j]*i ] = 1; if (i%prime[j]==0){ mu[i*prime[j]] = 0; break; } mu[i*prime[j]] = -mu[i]; } } for (int i=1;i<N;i++)sum[i]=sum[i-1]+mu[i];}LL calc(int a,int b){ if (a>b)swap(a,b); int last=0; LL ans=0; for (int i=1;i<=a;i=last+1){ last=min(a/(a/i),b/(b/i)); ans+=(LL)(a/i)*(b/i)*(sum[last]-sum[i-1]); } return ans;}void work(){ int a,b,c,d,K; //cin>>a>>b>>c>>d>>K; scanf("%d%d%d%d%d",&a,&b,&c,&d,&K); LL ans = calc(b/K,d/K)-calc(b/K,(c-1)/K)-calc((a-1)/K,d/K)+calc((a-1)/K,(c-1)/K); printf("%lld\n",ans); // //cout<<calc(b/K,d/K)-calc(b/K,(c-1)/K)-calc((a-1)/K,d/K)+calc((a-1)/K,(c-1)/K)<<endl; //cout<<calc(b/K,d/K)<<" "<<calc(b/K,(c-1)/K)<<" "<<calc((a-1)/K,d/K)<<" "<<calc((a-1)/K,(c-1)/K)<<endl;}int main(){ //freopen("1.txt","r",stdin); Mu(); int Case;cin>>Case; while (Case--){ work(); } return 0;}
阅读全文
0 0
- bzoj2301
- bzoj2301
- bzoj2301
- bzoj2301
- BZOJ2301 Problemb
- 【HAOI2011】【BZOJ2301】ProblemB
- BZOJ2301【HAOI2011】Problem b
- bzoj2301: [HAOI2011]Problem b
- [BZOJ2301][HAOI2011]Problem b
- bzoj2301【HAOI2011】Problem b
- Problem b [HAOI2011][bzoj2301]
- 【bzoj2301】 [HAOI2011]Problem b
- bzoj2301 [HAOI2011]Problem b
- 【bzoj2301】[HAOI2011]Problem b
- BZOJ2301: [HAOI2011]Problem b
- bzoj2301 [HAOI2011]Problem b
- BZOJ2301 Problem b
- HYSBZ/BZOJ2301 problem b
- struts2学习--注解开发
- 新增记录到TRIP数据库(JAVA)
- Myeclipse添加Mysql数据库时出现“Unable to create connection .Check your URL”
- Spring-AOP
- IT牛们的bat面试心得与经验总结
- bzoj2301
- 线程
- CS Academy Round #32 Light Count
- 推荐一款调试法宝--虚拟示波器
- CentOS7安装EPEL源
- Toggle+Switch
- 模拟CMOS集成电路设计 学习笔记(一)
- RecyclerView的点击事件和长按事件
- 学习淘淘商城第九十五课(jsonp的原理及两种实现方式)