【题目分析】

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);
	}
}

  

BZOJ 1101 [POI2007]Zap ——Dirichlet积的更多相关文章

  1. BZOJ 1101: [POI2007]Zap

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2262  Solved: 895[Submit][Status] ...

  2. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  3. BZOJ 1101 [POI2007]Zap(莫比乌斯反演)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1101 [题目大意] 求[1,n][1,m]内gcd=k的情况 [题解] 考虑求[1,n ...

  4. bzoj 1101 [POI2007]Zap——反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 #include<cstdio> #include<cstring& ...

  5. BZOJ 1101 [POI2007]Zap | 第一道莫比乌斯反(繁)演(衍)

    题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1101 题解: http://www.cnblogs.com/mrha/p/8203612.h ...

  6. 1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...

  7. 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...

  8. 【BZOJ】1101 [POI2007]Zap(莫比乌斯反演)

    题目 传送门:QWQ 分析 莫比乌斯反演. 还不是很熟练qwq 代码 //bzoj1101 //给出a,b,d,询问有多少对二元组(x,y)满足gcd(x,y)=d.x<=a,y<=b # ...

  9. 1101: [POI2007]Zap

    Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a ,y<=b,并且gcd(x,y)=d.作为FGD的同 ...

随机推荐

  1. mysql 入门 基本命令

    MYSQL入门学习之一:基本操作  1.登录数据库    www.2cto.com     命令:mysql -u username –p (mysql -h主机地址 -u用户名 -p用户密码)   ...

  2. AutoTile 自动拼接(二) 学习与实践

    开始代码前,我们要做点准备工作. 下面 跟着我做. 首先我 扣了一个 图. 这个是 做 水的资源,所以是动态的,我把其余两张也扣了出来. 看起来一样,不是,这样看肯定 看不出所以然,你们先放到u3d中 ...

  3. jenkins插件 build-name-setter

    #${BUILD_NUMBER}-${PROJECT_NAME}-${ENV,var="VARIABLENAME"}-${ENV,var="BUILD_USER" ...

  4. 5--OC--构造方法

    //  Created by Stephen on 16/3/2.//  Copyright © 2016年 Stephen. All rights reserved.//// 回顾上一章节Perso ...

  5. elasticearch 安装

    1.elasticsearch需要安装jdk1.7以上 2.在ubuntu下不能以root运行,需要建立专门账号 添加组 root@ubuntu:~/Downloads/elasticsearch-/ ...

  6. JavaScript(四)---- 函数

    函数主要用来封装具体的功能代码. 函数是由这样的方式进行声明的:关键字 function.函数名.一组参数,以及置于括号中的待执行代码. 格式: function 函数名(形参列表){         ...

  7. php使用curl提交xml数据

    $xml_data ='<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_ ...

  8. bash报错./mq.sh: line 15: warning: here-document at line 10 delimited by end-of-file (wanted `eof')

    [root@localhost tmp]# ./mq.sh./mq.sh: line 15: warning: here-document at line 10 delimited by end-of ...

  9. Android导入工程,R 资源文件无法生成

    在Android中使用开源代码或者自己开发项目的时候,经常会遇到R.java文件丢失的情况,如何重新生成呢?网上一般给出这样的两种方法: 方法 1:右击你的工程(项目)——>Android To ...

  10. 对Viewcontroller在UINavigationController中入栈出栈的一点点理解

    转载自:http://blog.csdn.net/intheair100/article/details/41119073 wait_record_arr 在viewdidload里面被alloc,如 ...