当前位置:网站首页>[Mobius inversion]
[Mobius inversion]
2022-06-25 08:03:00 【Mfy's little brother 1】
A. Luogu P2522 [HAOI2011]Problem b
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=50000+5;
int mu[maxn],prime[maxn],cnt,vis[maxn],n,m,f[maxn],k,a,b,c,d;
void init(){
// Linear sieve Mobius function
f[1]=mu[1]=1;
for(int i=2;i<=maxn;i++){
if(vis[i]==0){
prime[++cnt]=i;
mu[i]=-1;
}
for(int j=1;j<=cnt;j++){
if(i*prime[j]>maxn)break;
vis[i*prime[j]]=1;
mu[i*prime[j]]=i%prime[j]?-mu[i]:0;
if(i%prime[j]==0)break;
}
f[i]=f[i-1]+mu[i];
}
}
int getsum(int x,int y){
int ans=0;
for(int l=1,r;l<=min(x,y);l=r+1){
r=min(x/(x/l),y/(y/l));
ans+=(f[r]-f[l-1])*(x/l)*(y/l);
}
return ans;
}
int main(){
init();
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
printf("%d\n",getsum(b/k,d/k)-getsum((a-1)/k,d/k)-getsum((c-1)/k,b/k)+getsum((a-1)/k,(c-1)/k));
}
}
B. Luogu P3327 [SDOI2015] About a number and ( The number of factors for each number of preprocessing )
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=20101009;
const int maxn=1e7+5;
int mu[maxn],prime[maxn],cnt,vis[maxn],n,m,k,t[maxn],d[maxn];
ll he[maxn],f[maxn];
void init(int k) {
//mu[]: Mobius ,f[]:mu[] The prefix and ,d[]: Number of factors for each number ,he[]:d[] And ,t[]: The prime factor with the smallest number
vis[0]=vis[1]=mu[1]=d[1]=1;
for(int i=2;i<=k;i++) {
if (!vis[i])prime[++cnt]=i,mu[i]=-1,d[i]=2,t[i]=1;
for(int j=1;j<=cnt&&i*prime[j]<=k;j++) {
vis[i*prime[j]]=1;
if(i%prime[j]==0){
mu[i*prime[j]]=0;
d[i*prime[j]]=d[i]/(t[i]+1)*(t[i]+2);
t[i*prime[j]]=t[i]+1;
break;
}
else mu[i*prime[j]]=-mu[i],d[i*prime[j]]=d[i]<<1,t[i*prime[j]]=1;
}
}
for(int i=1;i<=k;i++)f[i]=f[i-1]+mu[i],he[i]=he[i-1]+d[i];
}
int main(){
init(50000);
int T;
scanf("%d",&T);
while(T--){
ll ans=0;
scanf("%d%d",&n,&m);
if(n>m)swap(n,m);
for(int l=1,r;l<=n;l=r+1){
r=min(n/(n/l),m/(m/l));
ans+=1ll*(f[r]-f[l-1])*he[n/l]*he[m/l];
}
printf("%lld\n",ans);
}
}
边栏推荐
- 三台西门子消防主机FC18配套CAN光端机进行光纤冗余环网组网测试
- Authority design of SaaS system based on RBAC
- Set the textalign property of the label control in C to control the method of text centering
- 基于Anaconda的模块安装与注意事项
- 电子学:第011课——实验 10:晶体管开关
- 2021ICPC网络赛第一场
- How to select lead-free and lead-free tin spraying for PCB? 2021-11-16
- [little knowledge] PCB proofing process
- 深度学习系列48:DeepFaker
- 【补题】2021牛客暑期多校训练营4-n
猜你喜欢

c#搭建ftp服务器并实现文件上传和下载

电子学:第012课——实验 13:烧烤 LED

Mining microbial dark matter -- a new idea

基于STM32MP157调试MIPI-DSI屏幕

Looking for b-end product manager after years? I almost ruined myself

Force buckle 272 Closest binary search tree value II recursion

Requirements for Power PCB circuit board design 2021-11-09

Electronics: Lesson 012 - Experiment 11: light and sound

用函数的递归来解决几道有趣的题

FM信号、调制信号和载波
随机推荐
【红旗杯?】补题
Opencv minimum filtering (not limited to images)
Electronics: Lesson 013 - Experiment 14: Wearable pulsed luminaries
Drawing of clock dial
力扣 272. 最接近的二叉搜索树值 II 递归
TCP的那点玩意儿
消息中间件之ActiveMQ的基本使用
Matlab代码格式一键美化神器
PH neutralization process modeling
C#中如何调整图像大小
Share the process requirements for single-layer flexible circuit board
Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
Is it safe to open an account through the haircut account opening link now?
C examples of using colordialog to change text color and fontdialog to change text font
Set the textalign property of the label control in C to control the method of text centering
MySQL interview - the response of executing SQL is relatively slow, and the troubleshooting ideas.
基于RBAC 的SAAS系统权限设计
Force buckle 272 Closest binary search tree value II recursion
将数据导入到MATLAB
【补题】2021牛客暑期多校训练营4-n