首页 技术 正文
技术 2022年11月10日
0 收藏 588 点赞 2,593 浏览 1279 个字

【题目分析】

Dirichlet积+莫比乌斯函数。

对于莫比乌斯函数直接筛出处理前缀和。

对于后面向下取整的部分,可以分成sqrt(n)+sqrt(m)部分分别计算

学习了一下线性筛法。

积性函数可以在O(n)的时间内算出。

【代码】

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <map>#include <set>#include <queue>#include <string>#include <iostream>#include <algorithm>using namespace std;#define maxn 50005#define inf 0x3f3f3f3f#define F(i,j,k) for (int i=j;i<=k;++i)#define D(i,j,k) for (int i=j;i>=k;--i)void Finout(){    #ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);//    freopen("wa.txt","w",stdout);//    freopen("ac.txt","w",stdout);    #endif}int Getint(){    int x=0,f=1; char ch=getchar();    while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}    while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}    return x*f;}int pmu[maxn],mu[maxn],vis[maxn],pri[maxn],top=0;void init(){mu[1]=1;vis[1]=1;F(i,2,maxn-1){if (!vis[i]) {vis[i]=1;pri[++top]=i;mu[i]=-1;}for (int j=1;j<=top&&i*pri[j]<maxn;++j){vis[i*pri[j]]=1;if (i%pri[j]==0) {break;}else mu[pri[j]*i]=-mu[i];}}F(i,1,maxn-1) pmu[i]=pmu[i-1]+mu[i];}int t;int main(){init();    Finout();    t=Getint();    while (t--)    {    int ans=0;    int a=Getint(),b=Getint(),d=Getint();    a/=d; b/=d;    int la,lb,nowa,nowb,l,r=a;    while (r)    {//    cout<<"r is "<<r<<endl;    nowa=a/r;nowb=b/r;    la=a/(nowa+1)+1;lb=b/(nowb+1)+1;//    cout<<"la is "<<la<<" lb is "<<lb<<endl;    l=max(la,lb);    ans+=nowa*nowb*(pmu[r]-pmu[l-1]);    r=l-1;}printf("%d\n",ans);}}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,076
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894