Hillan and the girl

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Problem Description
“WTF!
While everyone has his girl(gay) friend, I only have my keyboard!”
Tired of watching others' affair, Hillan burst into scream, which made
him decide not to hold it back.
“All right, I am giving you a
question. If you answer correctly, I will be your girl friend.” After
listening to Hillan, Girl replied, “What is the value of ∑ni=1∑mj=1f(i,j), where f(i,j)=0 if gcd(i,j) is a square number and f(i,j)=1 if gcd(i,j) is not a square number(gcd(i,j) means the greatest common divisor of x and y)?”
But Hillan didn't have enough Intelligence Quotient to give the right answer. So he turn to you for help.
 
Input
The first line contains an integer T(1≤T≤10,000)——The number of the test cases.
For each test case, the only line contains two integers n,m(1≤n,m≤10,000,000) with a white space separated.
 
Output
For each test case, the only line contains a integer that is the answer.
 
Sample Input
2
1 2333333
10 10
 
Sample Output
0
33

Hint

In the first test case, obviously $f\left(i,j\right)$ always equals to 0, because $i$ always equals to 1 and $\gcd\left(i,j\right)$ is always a square number(always equals to 1).

 
Source
                  min(n,m) min(n/k,m/k)
思路:首先推到∑     ∑ mu(d)  * [n/k/d] * [m/k/d];  k为完全平方数;
      k=1   d=1
   令T=k*d;
   可得:
      min(n,m)                    
      ∑   [n/T] * [m/T]  ∑   mu(T/k)  ;
      T          k|T
      令gg数组等于 ∑   mu(T/k)  相当于原来的mu函数;
             k|T
      和原来一样分块即可;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e7+,M=1e7+,inf=1e9+,mod=1e9+;
int mu[N], p[N], np[N], cnt, sum[N];
ll gg[N];
void init() {
mu[]=;
for(int i=; i<N; ++i) {
if(!np[i]) p[++cnt]=i, mu[i]=-;
for(int j=; j<=cnt && i*p[j]<N; ++j) {
int t=i*p[j];
np[t]=;
if(i%p[j]==) { mu[t]=; break; }
mu[t]=-mu[i];
}
}
for(int i=;i*i<N;i++)
{
for(int t=i*i;t<N;t+=(i*i))
sum[t]+=mu[t/i/i];
}
for(int i=;i<N;i++)
gg[i]=gg[i-]+sum[i]; }
ll getans(ll b,ll d)
{
if(b>d)swap(b,d);
ll ans=;
for(ll L=,R=;L<=b;L=R+)
{
R=min(b/(b/L),d/(d/L));
ans+=(b/L)*(d/L)*(gg[R]-gg[L-]);
}
return ans;
}
int main()
{
int T;
init();
scanf("%d",&T);
while(T--)
{
ll b,d;
scanf("%I64d%I64d",&b,&d);
printf("%I64d\n",(b*d)-getans(b,d));
}
return ;
}

hdu 5663 Hillan and the girl 莫比乌斯反演的更多相关文章

  1. HDU 5663 Hillan and the girl (莫比乌斯反演 + 分块)

    题意:给定n,m,求,其中F(x)=0,,如果x是完全平方数,否则是1. 析: 由于按照题意的F,不好筛选,所以我们反过来,F(x),x是平方数,就是1,否则是0. 这个是可以预处理出来的,可以用筛选 ...

  2. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  3. HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解

    题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...

  4. HDU 2841 Visible Trees(莫比乌斯反演)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...

  5. HDU 5321 Beautiful Set (莫比乌斯反演 + 逆元 + 组合数学)

    题意:给定一个 n 个数的集合,然后让你求两个值, 1.是将这个集合的数进行全排列后的每个区间的gcd之和. 2.是求这个集合的所有的子集的gcd乘以子集大小的和. 析:对于先求出len,len[i] ...

  6. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. HDU 4746 Mophues (莫比乌斯反演应用)

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  8. HDU 4746 Mophues【莫比乌斯反演】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意: 1≤x,y≤n , 求gcd(x,y)分解后质因数个数小于等k的(x,y)的对数. 分 ...

  9. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

随机推荐

  1. Directory和HashTable的区别

    1:单线程程序中推荐使用 Dictionary, 有泛型优势, 且读取速度较快, 容量利用更充分.2:多线程程序中推荐使用 Hashtable, 默认的 Hashtable 允许单线程写入, 多线程读 ...

  2. AJAX 异步传数组时候,后台接收不到!

    呵呵,那么问题又来了! 这是为啥呢!! var ids= []; $.ajax({ url: 'xxxx.do', data: { ids: ids}, dataType: "json&qu ...

  3. linux下tmp目录里很多php开头的文件

    cd /tmp; ll -ash; 51M -rw------- 1 nginx nginx 51M Sep 17 09:33 php3p7FPA 51M -rw------- 1 nginx ngi ...

  4. 实用的 集合工具类 和 String工具类

    集合工具类:CollectionUtil method: 1.isNotEmpty() 不为空 2.isEmpty() 为空 举例:map集合         Map<String,String ...

  5. 基础篇-java开发

    开局必知 1.变量 在java中,以{}为作用域,所以就存在成员变量和局部变量之说 由于java是强类型语言,所以在申明变量的时候,必须指定类型 java里,一个变量有声明过程和初始化过程(也就是赋值 ...

  6. .net 取得类的属性、方法、成员及通过属性名取得属性值

    //自定义的类 model m = new model();   //取得类的Type实例 //Type t = typeof(model);    //取得m的Type实例 Type t = m.G ...

  7. MySQL中因为unique key 非空唯一索引存在导致修改主键失败案例

    研发在早期的设计中,由于设计方面的问题,导致在设计表结构的时候,有个表有非空唯一索引而没有主键 在InnoDB存储引擎中,如果没有主键的情况下,有非空唯一索引的话,非空唯一索引即为主键. 那么这就会有 ...

  8. Python中的魔术(双下划线'__xxx__')方法详解

    介绍 在Python中,所有以“__”双下划线包起来的方法,都统称为“Magic Method”,中文称『魔术方法』,例如类的初始化方法 __init__ ,Python中所有的魔术方法均在官方文档中 ...

  9. return和yield的区别

    # return 返回给调用者值,并结束此函数.#yiled 返回给调用者值,并将指针停留着当前位置.

  10. (4.16)sql server迁移DB文件(同一DB内)

    SQL Server 修改数据库物理文件存在位置 关键词:迁移文件,迁移temp库(这怎么迁移呢,用方法2即可,需要重启实例) 三种均需要离线: 一共分为(1)脱机迁移和(2)在线迁移. (1)迁移方 ...