题目描述

神犇YY虐完数论后给傻×kAc出了一题

给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对

kAc这种傻×必然不会了,于是向你来请教……

多组输入

输入输出格式

输入格式:

第一行一个整数T 表述数据组数

接下来T行,每行两个正整数,表示N, M

输出格式:

T行,每行一个整数表示第i组数据的结果

输入输出样例

输入样例#1:
复制

2
10 10
100 100
输出样例#1: 复制

30
2791

说明

T = 10000

N, M <= 10000000

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ bool vis[10000002];
int mu[10000002];
ll sum[10000002];
int p[10000002];
int f[10000001];
int tot;
void init() {
mu[1] = 1;
for (int i = 2; i <= 10000000; i++) {
if (!vis[i]) {
p[++tot] = i; mu[i] = -1;
}
for (int j = 1; j <= tot; j++) {
if (i*p[j] > 10000000)break;
vis[i*p[j]] = 1;
if (i%p[j] == 0) {
mu[i*p[j]] = 0; break;
}
else {
mu[i*p[j]] = -mu[i];
}
}
}
for (int i = 1; i <= tot; i++) {
for (int j = 1; j*p[i] <= 10000000; j++) {
f[j*p[i]] += mu[j];
}
}
for (int i = 1; i <= 10000000; i++)
sum[i] = sum[i - 1] + 1ll * f[i];
} int main()
{
// ios::sync_with_stdio(0);
init();
int T = rd();
while (T--) {
int N = rd(), M = rd();
ll ans = 0;
for (int l = 1, r; l <= min(N, M); l = r + 1) {
r = min(N / (N / l), M / (M / l));
ans += 1ll * (sum[r] - sum[l - 1])*(N / l)*(M / l);
}
printf("%lld\n", ans * 1ll);
}
return 0;
}

YY的GCD 数学的更多相关文章

  1. Bzoj 2820: YY的GCD(莫比乌斯反演+除法分块)

    2820: YY的GCD Time Limit: 10 Sec Memory Limit: 512 MB Description 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x& ...

  2. BZOJ 2820: YY的GCD [莫比乌斯反演]【学习笔记】

    2820: YY的GCD Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1624  Solved: 853[Submit][Status][Discu ...

  3. [BZOJ2820]YY的GCD

    [BZOJ2820]YY的GCD 试题描述 神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少 ...

  4. bzoj 2820 YY的GCD 莫比乌斯反演

    题目大意: 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对 这里就抄一下别人的推断过程了 后面这个g(x) 算的方法就是在线性 ...

  5. 【BZOJ】【2820】YY的GCD

    莫比乌斯反演 PoPoQQQ讲义第二题. 暴力枚举每个质数,然后去更新它的倍数即可,那个g[x]看不懂就算了…… 为什么去掉了一个memset就不T了→_→…… /****************** ...

  6. 【莫比乌斯反演】关于Mobius反演与gcd的一些关系与问题简化(bzoj 2301 Problem b&&bzoj 2820 YY的GCD&&BZOJ 3529 数表)

    首先我们来看一道题  BZOJ 2301 Problem b Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd( ...

  7. 【BZOJ 2820】 YY的GCD (莫比乌斯+分块)

    YY的GCD   Description 神犇YY虐完数论后给傻×kAc出了一题 给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少 ...

  8. 【BZOJ2820】YY的GCD(莫比乌斯反演)

    [BZOJ2820]YY的GCD(莫比乌斯反演) 题面 讨厌权限题!!!提供洛谷题面 题解 单次询问\(O(n)\)是做过的一模一样的题目 但是现在很显然不行了, 于是继续推 \[ans=\sum_{ ...

  9. YY的GCD

    YY的GCD 给出T个询问,询问\(\sum_{i=1}^N\sum_{j=1}^M(gcd(i,j)\in prime)\),T = 10000,N, M <= 10000000. 解 显然质 ...

随机推荐

  1. 21-从零玩转JavaWeb-多态详解

    配套视频详解 多态思想 eclipse快捷键设置 多态的好处 多态方法调用 instanceof关键字 多态中字段注意点 一.什么是多态   既然子类是一种特殊的父类   那么我们可不可以认为   狗 ...

  2. elasticsearch2.x插件之一:kopf

    kopf kopf is a simple web administration tool for elasticsearch written in JavaScript + AngularJS + ...

  3. linux lvs 配置

    redhatAS4.2 安装集群LVS 环境描述: 本文在配置LVS时使用三台linux,一台做Directorserver (192.168.0.25) ,两台做realserver(192.168 ...

  4. swfupload上传文件数量限制之setStats()

    使用swfupload仿赶集的图片上传 SWFUpload是一个基于flash与javascript的客户端文件上传组件. handlers.js文件 完成文件入列队(fileQueued) → 完成 ...

  5. 记一篇Python学习的简易版教程

    廖雪峰的教学博客https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143178 ...

  6. java 解析xml(dom4j.jar)

    先导入jar包 <?xml version="1.0" encoding="UTF-8"?> <companys> <compan ...

  7. 在CenOS7.5里安装Redis

    一.系统环境 操作系统:CentOS 7.5 Redis版本:redis3.2.8 登录账号:Frank 二.安装过程 A.预安装,安装gcc 1.进入终端,切换到root账号 2.输入指令: yum ...

  8. 下载Redis

    1.下载当前Redis 官网:https://redis.io/ 当前稳定版本是4.0.11,如下图,点Download it下面的链接进行下载 2.下载历史版本的Resis 网址: http://d ...

  9. Luogu 4284 [SHOI2014]概率充电器

    BZOJ 3566 树形$dp$ + 概率期望. 每一个点的贡献都是$1$,在本题中期望就等于概率. 发现每一个点要通电会在下面三件事中至少发生一件: 1.它自己通电了. 2.它的父亲给它通电了. 3 ...

  10. combogrid change check multiple

    this.SetDict = function (obj, dicType, multiple, Ischeckbox, callback, change) { obj.combogrid({ pan ...