[BZOJ1101][POI2007]Zap

试题描述

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

输入

第一行包含一个正整数n,表示一共有n组询问。(1<=n<= 50000)接下来n行,每行表示一个询问,每行三个
正整数,分别为a,b,d。(1<=d<=a,b<=50000)

输出

对于每组询问,输出到输出文件zap.out一个正整数,表示满足条件的整数对数。

输入示例


输出示例


数据规模及约定

见“输入

题解

[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的更多相关文章

  1. BZOJ1101 POI2007 Zap 【莫比乌斯反演】

    BZOJ1101 POI2007 Zap Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b, ...

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

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

  3. Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...

  4. BZOJ1101 [POI2007]Zap 和 CF451E Devu and Flowers

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

  5. 【莫比乌斯反演】BZOJ1101 [POI2007]zap

    Description 回答T组询问,有多少组gcd(x,y)=d,x<=a, y<=b.T, a, b<=4e5. Solution 显然对于gcd=d的,应该把a/d b/d,然 ...

  6. 莫比乌斯反演学习笔记+[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 ...

  7. BZOJ 1101: [POI2007]Zap

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

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

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

  9. [POI2007]Zap

    bzoj 1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descriptio ...

随机推荐

  1. SQL温故系列两篇(二)

    .Sql 插入语句得到自动生成的递增的ID值 Insert into Table(name,des,num) values(’ltp’,’thisisbest’,10); Select @@ident ...

  2. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  3. 实用的JS代码段(表单篇)

    整理了下比较实用的Javascript代码段,完整的代码参考 1 多个window.onload方法 由于onload方法时在页面加载完成后,自动调用的.因此被广泛的使用,但是弊端是只能实用onloa ...

  4. beta版本贡献率

    队名:攻城小分队 031302410 郭怡锋 : 占比:50% 031302411 洪大钊: 占比:30% 031302206 陈振贵: 占比:10% 031302416 黄伟祥: 占比:10%

  5. 读MBE

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  6. hdu2444 判断二分图+最大匹配

    #include<stdio.h> #include<string.h> #include<queue> using namespace std; #define ...

  7. 【CodeForces 621A】Wet Shark and Odd and Even

    题 Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wan ...

  8. Oracle自定义函数

    核心提示:函数用于返回特定数据.执行时得找一个变量接收函数的返回值; 语法如下: create or replace function function_name ( argu1 [mode1] da ...

  9. POJ2411 Mondriaan's Dream

    Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...

  10. php版本的discuzX3.2部署的问题收集

    1.登陆后台老是自动退出是怎么回事? 解决方法:用ftp上線下載文件下在跟目錄/config/config_global.php把$_config['admincp']['checkip']  = 1 ...