【BZOJ1101】Zap(莫比乌斯反演)
题意:多组询问,对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d。
T,a,b,d,x,y<=50000
思路:下底函数分块+积性函数前缀和
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 110000
#define M 410000
#define eps 1e-8
#define pi acos(-1)
#define oo 1e9 int mu[N+],s[N+],prime[N+],flag[N+]; ll calc(int n,int m)
{
if(n>m) swap(n,m);
ll ans=;
int i=;
while(i<=n)
{
ll x=n/i;
ll y=m/i;
int t1=n/x;
int t2=m/y;
int pos=min(t1,t2);
ans+=x*y*(s[pos]-s[i-]);
i=pos+;
}
return ans;
} int main()
{
int cas;
scanf("%d",&cas);
mu[]=;
int m=;
for(int i=;i<=N;i++)
{
if(!flag[i])
{
prime[++m]=i;
mu[i]=-;
}
for(int j=;j<=m;j++)
{
int t=prime[j]*i;
if(t>N) break;
flag[t]=;
if(i%prime[j]==)
{
mu[t]=;
break;
}
mu[t]=-mu[i];
}
}
for(int i=;i<=N;i++) s[i]=s[i-]+mu[i];
while(cas--)
{
int a,b,k;
scanf("%d%d%d",&a,&b,&k);
a/=k; b/=k;
ll ans=calc(a,b);
printf("%lld\n",ans);
}
return ;
}
【BZOJ1101】Zap(莫比乌斯反演)的更多相关文章
- 【题解】Zap(莫比乌斯反演)
[题解]Zap(莫比乌斯反演) 裸题... 直接化吧 [P3455 POI2007]ZAP-Queries 所有除法默认向下取整 \[ \Sigma_{i=1}^x\Sigma_{j=1}^y[(i, ...
- BZOJ1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2951 Solved: 1293[Submit][Status ...
- Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...
- 【BZOJ1101】Zap [莫比乌斯反演]
Zap Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 对于给定的整数a,b和d,有多少正整 ...
- 1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...
- bzoj 1101 Zap —— 莫比乌斯反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...
- BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)
手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...
- BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )
求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...
- BZOJ 1101 Zap(莫比乌斯反演)
http://www.lydsy.com/JudgeOnline/problem.php?id=1101 给定a,b,d,求有多少gcd(x,y)==d(1<=x<=a&& ...
- 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)
先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...
随机推荐
- iOS开发遇到的坑之六--使用cocopods管理第三方库时,编译出现Library not found for -lPods问题的解决办法
在项目中有时候会遇到Library not found for -lPods(这里的IPods指的是你具体的第三方库)的问题 出现这个错误的原因是:xcode在编译的时候找不到这个库,从而导致项目无法 ...
- jq 下拉框
<div class="alls"> <div class="item"> <div class="all"& ...
- Unity基础-Input接口
input 底层的设备输入接口,在开发中很少用到 Input.GetKey() // Update is called once per frame void Update () { if (Inpu ...
- vue_music:封装scroll.vue组件
在项目中经常用到滚动,结合Better-scroll封装了sroll.vue组件参考链接:https://ustbhuangyi.github.io...http://www.imooc.com/ar ...
- ASP( VBScript ) 解析 JSON
<script language="jscript" runat="server"> Array.prototype.get = function( ...
- paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之fsm summary
主要是1.不要用1段式写FSM 2.不要用状态编码写one-hot FSM ,要用索引编码写one-hot FSM.
- 汇编语言 Part 1——简介、基本语法、内存分段与内存地址
简介 什么是汇编语言? 汇编语言是一种低级的编程语言,在程序的语句和体系结构的机器代码指令之间有很强的对应关系. 每种汇编语言都特定于特定的计算机体系结构,但需要解释或编译.汇编语言也可以称为符号机器 ...
- Tomcat Bug记录
1.问题:org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-IN ...
- 在SCIKIT中做PCA 逆变换 -- 新旧特征转换
PCA(Principal Component Analysis)是一种常用的数据分析方法.PCA通过线性变换将原始数据变换为一组各维度线性无关的表示,可用于提取数据的主要特征分量,常用于高维数据的降 ...
- LeetCode(283)Move Zeroes
题目 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...