[BZOJ1101][POI2007]Zap
[BZOJ1101][POI2007]Zap
试题描述
,y<=b,并且gcd(x,y)=d。作为FGD的同学,FGD希望得到你的帮助。
输入
正整数,分别为a,b,d。(1<=d<=a,b<=50000)
输出
输入示例
输出示例
数据规模及约定
见“输入”
题解
[BZOJ2820]YY的GCD简化版。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std; const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
int read() {
int x = 0, f = 1; char c = Getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = Getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = Getchar(); }
return x * f;
} #define maxn 50010
#define LL long long
int n; int prime[maxn], cnt, u[maxn], sum[maxn];
bool vis[maxn];
void u_table() {
int N = maxn - 10;
u[1] = 1;
for(int i = 2; i <= N; i++) {
if(!vis[i]) prime[++cnt] = i, u[i] = -1;
for(int j = 1; j <= cnt && (LL)prime[j] * (LL)i <= (LL)N; j++)
if(i % prime[j]) vis[i*prime[j]] = 1, u[i*prime[j]] = -u[i];
else{ vis[i*prime[j]] = 1, u[i*prime[j]] = 0; break; }
}
for(int i = 1; i <= N; i++) sum[i] = sum[i-1] + u[i];
return ;
} int main() {
u_table();
n = read(); while(n--) {
int a = read(), b = read(), d = read();
if(a > b) swap(a, b); a /= d; b /= d;
int p = 1;
LL ans = 0;
for(; p <= a;) {
int np = p;
p = min(a / (a / np), b / (b / np));
ans += (LL)(sum[p] - sum[np-1]) * (LL)(a / np) * (LL)(b / np);
p++;
// printf("%d\n", p);
}
printf("%lld\n", ans);
} return 0;
}
[BZOJ1101][POI2007]Zap的更多相关文章
- BZOJ1101 POI2007 Zap 【莫比乌斯反演】
BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...
- 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 [POI2007]Zap 和 CF451E Devu and Flowers
Zap FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d.作为FGD的同学,FGD希望得到 ...
- 【莫比乌斯反演】BZOJ1101 [POI2007]zap
Description 回答T组询问,有多少组gcd(x,y)=d,x<=a, y<=b.T, a, b<=4e5. Solution 显然对于gcd=d的,应该把a/d b/d,然 ...
- 莫比乌斯反演学习笔记+[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 ...
- 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, 化简一下得 ...
- [POI2007]Zap
bzoj 1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...
随机推荐
- asp.net 预编译和动态编译
在asp.net中,编译可以分为:动态编译Dynamical Compilation和预编译(Precompilation). 动态编译 深入剖析ASP.NET的编译原理之一:动态编译(Dynamic ...
- Bootstrap3.0学习第十七轮(JavaScript插件——模态框)
详情请查看http://aehyok.com/Blog/Detail/24.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- 第二课:判断js变量的类型以及domReady的原理
1.类型的判断: js五种简单数据类型有:null,undefined,boolean,number,string. 还有复杂的数据类型:Object,Function,RegExp,Date,自定义 ...
- iOS - 获取手机中所有图片
1 #import <AssetsLibrary/AssetsLibrary.h> /** 6 * ALAssetsLibrary.h 代表资源库(所有的视频,照片) 7 ALAssets ...
- Ibatis学习总结2--SQL Map XML 配置文件
SQL Map 使用 XML 配置文件统一配置不同的属性,包括 DataSource 的详细配置信息, SQL Map 和其他可选属性,如线程管理等.以下是 SQL Map 配置文件的一个例子: Sq ...
- c# 多线程 调用带参数函数
线程操作主要用到Thread类,他是定义在System.Threading.dll下.使用时需要添加这一个引用.该类提供给我们四个重载的构造函数(以下引自msdn). Thread (Pa ...
- Maven-改变本地存储仓库位置
修改 maven 仓库存放位置: 找到 maven 下的 conf 下的 settings.xml 配置文件,假设maven安装在D:\Server目录中.那么配置文件应该在 D:\Server\ma ...
- 【CodeForces 577B】Modulo Sum
题 题意 给你n(1 ≤ n ≤ 106)个数a1..an(0 ≤ ai ≤ 109),再给你m( 2 ≤ m ≤ 103)如果n个数的子集的和可以被m整除,则输出YES,否则NO. 分析 分两种情况 ...
- codevs1746 贪吃的九头龙
[问题描述]传说中的九头龙是一种特别贪吃的动物.虽然名字叫“九头龙”,但这只是说它出生的时候有九个头,而在成长的过程中,它有时会长出很多的新头,头的总数会远大于九,当然也会有旧头因衰老而自己脱落.有一 ...
- Type-Length-Value编码
Within data communication protocols, optional information may be encoded as a type-length-value or T ...