BZOJ 1101 [POI2007]Zap ——Dirichlet积
【题目分析】
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积的更多相关文章
- BZOJ 1101: [POI2007]Zap
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2262 Solved: 895[Submit][Status] ...
- BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )
求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...
- BZOJ 1101 [POI2007]Zap(莫比乌斯反演)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1101 [题目大意] 求[1,n][1,m]内gcd=k的情况 [题解] 考虑求[1,n ...
- bzoj 1101 [POI2007]Zap——反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 #include<cstdio> #include<cstring& ...
- BZOJ 1101 [POI2007]Zap | 第一道莫比乌斯反(繁)演(衍)
题目: http://www.lydsy.com/JudgeOnline/problem.php?id=1101 题解: http://www.cnblogs.com/mrha/p/8203612.h ...
- 1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...
- 【BZOJ】1101: [POI2007]Zap(莫比乌斯+分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=1101 无限膜拜数论和分块orz 首先莫比乌斯函数的一些性质可以看<初等数论>或<具 ...
- 【BZOJ】1101 [POI2007]Zap(莫比乌斯反演)
题目 传送门:QWQ 分析 莫比乌斯反演. 还不是很熟练qwq 代码 //bzoj1101 //给出a,b,d,询问有多少对二元组(x,y)满足gcd(x,y)=d.x<=a,y<=b # ...
- 1101: [POI2007]Zap
Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a ,y<=b,并且gcd(x,y)=d.作为FGD的同 ...
随机推荐
- [转]java static final 初始化
http://tanbing1986411.blog.163.com/blog/static/7259798220103610224434/ java static final 初始化 1.stati ...
- 关于html5的几个新标签在IE9之前不支持的解决办法
IE8及之前的浏览器不支持用CSS的方法来使用这些尚未支持的结构元素,为了在Internet Explorer浏览器中也能正常使用这些结构元素,需要使用JavaScript脚本,如下:<scri ...
- 笔记整理--Http-Cookie
如何设置一个永远无法删除的Cookie -- 系统架构 -- IT技术博客大学习 -- 共学习 共进步! - Google Chrome (2013/6/20 9:46:38) 如何设置一个永远无法删 ...
- Windows下MongoDB安装及创建用户名和密码
下载MongoDB的安装文件https://www.mongodb.com/download-center#community,选择合适的版本(注:本人选择的是3.2.6) 下载完MongoDB.ms ...
- Windows 2003】利用域&&组策略自动部署软件
Windows 2003]利用域&&组策略自动部署软件 转自 http://hi.baidu.com/qu6zhi/item/4c0fa100dc768613cc34ead0 ==== ...
- Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)
D. Fix a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- nginx 504 Gateway Time-out 解决办法
今天用PHP执行一个非常耗时的文件[ps:自己有用,大概3分钟] 但是执行到一分钟后显示 nginx 504 Gateway Time-out 于是修改php-ini.php中的max_executi ...
- GuideActivity.java引导界面:
这是谷歌官方给我们提供的一个兼容低版本安卓设备的软件包,里面包囊了只有在安卓3.0以上可以使用的api. 而viewpager就是其中之一利用它,我们可以做很多事情,从最简单的导航,到页面菜单等等.那 ...
- 如何把一个TXT文本文件按行数分割成多个文本文件
2011-04-27 12:00:24| 分类: 默认分类 |字号 订阅 网上有很多文本分割软件都是按字节大小来分割的,主要用于小说类的文本分割,对于比较有规则的内容按行数进行分割非常不方便 ...
- Java去除字符串中的空格
特别注意了 Strim或者Trip都是只能去除头部和尾部的空字符串.中间的部分是不能够去除的! 推荐使用ApacheCommonse的StringUtils.deleteWhitespace(&quo ...