收获:

当一个东西的取值有限时,我们可以枚举它,然后统计它被计算了多少次。

 #include <cstdio>
#include <iostream>
using namespace std; typedef long long dnt; int prm[], isnot[], mu[], f[], ptot; void init( int n ) {
mu[] = ;
for( int i=; i<=n; i++ ) {
if( !isnot[i] ) {
prm[++ptot] = i;
mu[i] = -;
}
for( int j=; j<=ptot && i*prm[j]<=n; j++ ) {
isnot[i*prm[j]]=true;
if( i%prm[j]== ) {
mu[i*prm[j]] = ;
break;
}
mu[i*prm[j]] = -mu[i];
}
}
for( int i=; i<=ptot; i++ ) {
int p = prm[i];
for( int j=p; j<=n; j+=p )
f[j] += mu[j/p];
}
for( int i=; i<=n; i++ )
f[i] += f[i-];
}
dnt calc( dnt n, dnt m ) {
if( n>m ) swap(n,m);
dnt rt = ;
for( int i=; i<=n; i++ ) {
int ii = min( n/(n/i), m/(m/i) );
rt += (f[ii]-f[i-])*(n/i)*(m/i);
i = ii;
}
return rt;
}
int main() {
int T;
init( );
scanf( "%d", &T );
while( T-- ) {
int n, m;
scanf( "%d%d", &n, &m );
printf( "%lld\n", calc(n,m) );
}
}

bzoj 2820的更多相关文章

  1. 莫比乌斯反演 BZOJ 2820

    莫比乌斯反演真(TMD)难学.我自看了好长时间. BZOJ 2820: YY的GCD Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1384  Sol ...

  2. 【莫比乌斯反演】关于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( ...

  3. bzoj 2820 / SPOJ PGCD 莫比乌斯反演

    那啥bzoj2818也是一样的,突然想起来好像拿来当周赛的练习题过,用欧拉函数写掉的. 求$(i,j)=prime$对数 \begin{eqnarray*}\sum_{i=1}^{n}\sum_{j= ...

  4. [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块)

    [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块) 题面 给定N, M,求\(1\leq x\leq N, 1\leq y\leq M\)且gcd(x, y)为质数的(x, y)有多少对. ...

  5. bzoj 2820 YY的GCD - 莫比乌斯反演 - 线性筛

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

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

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

  7. BZOJ 2820 YY的GCD

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=2820 有种方法是枚举质数然后用BZOJ2301来做但是超时了... 具体式子大概张这样: ...

  8. BZOJ 2820 YY的GCD(莫比乌斯函数)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2820 题意:给定n,m.求1<=x<=n, 1<=y<=m且Gc ...

  9. ●BZOJ 2820 YY的GCD

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2820 题解: 莫比乌斯反演 先看看这个题:HDU 1695 GCD(本题简化版) HDU 1 ...

  10. 【刷题】BZOJ 2820 YY的GCD

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

随机推荐

  1. INIT_WORK

    借助runtime pm,在需要使用模块时,增加引用计数(可调用pm_runtime_get),不需要使用时,减少引用计数(可调用pm_runtime_put). 1.INIT_WORK(struct ...

  2. HTTP 请求 的方法Util

    HTTP请求 的一系列方法总结 /** * *******************************传统请求--开始************************************** ...

  3. C++循环链表解决约瑟夫环问题

    约瑟夫环问题可以简单的使用数组的方式实现,但是现在我使用循环链表的方法来实现,因为上午看到一道面试题规定使用循环链表解决约瑟夫环问题. 什么是约瑟夫环? “约瑟夫环是一个数学的应用问题:已知n个人(以 ...

  4. 创建一个简单的Maven工程

    Maven的工程结构如下图所示: 大致来看,Maven的工程结构如下: 在创建maven工程时,可以通过骨架创建,也可以不通过骨架创建. 我们先用idea通过骨架创建一个Maven工程. 配置pom. ...

  5. 半小时分组统计个数sql

    group by 最后一个时间是多少按多少分组 select count(1), trunc(a.refund_insert_time, 'hh24') + case when to_char(ref ...

  6. CentOS/RHEL Linux安装EPEL第三方软件源

    https://www.vpser.net/manage/centos-rhel-linux-third-party-source-epel.html

  7. iis应用池内存溢出卡死优化

    1.修改回收阀值memoryLimit 在ASP.NET Web服务器上,ASP.NET所能够用到的内存,通常不会等同于所有的内存数量.在machine.config(C:/WINDOWS/Micro ...

  8. css绝对居中img

    html: <div id="imgs"> <img src="http://pic.616pic.com/ys_b_img/00/03/60/Kt6Q ...

  9. js获取url链接地址的参数

    访问地址为:http://XXX.com?style=green <script language="javascript"> var getArgs = functi ...

  10. 使用 JQuery 实现将 table 按照列排序

    使用 JQuery 实现将 table 按照列排序 使用 JQuery 实现将 table 按照列排序 代码如下 <!DOCTYPE html> <html> <head ...